Changeset 90
- Timestamp:
- 1998-12-23T16:58:42+13:00 (25 years ago)
- Location:
- trunk/gsdl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/etc/site.cfg.example
r57 r90 1 # You should save this file as site.cfg and edit it 2 # to suit your site's configuration. This file may 3 # be placed in the GSDLHOME directory, the 4 # GSDLHOME/etc directory or in a particular collection's 5 # directory. 6 1 7 gsdlhome /home/rjmcnab/gsdl/collect/gberg 2 8 httpprefix http://162.105.138.14/gberg 3 9 gwcgi http://162.105.138.14/cgi-bin/gbergmain 10 11 # maxrequests is the most requests a fastcgi process 12 # will serve before it exits. This can be set to a 13 # low figure (like 1) while debugging and then set 14 # to a high figure (like 10000) when everything is 15 # working ok. 16 maxrequests 1 -
trunk/gsdl/src/library/Makefile
r89 r90 26 26 CC = gcc 27 27 CCFLAGS = -O2 28 DEFS = -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM 28 DEFS = -DNZDL -DQUIET -DSHORT_SUFFIX -DPARADOCNUM -DUSE_FASTCGI 29 29 RANLIB = ranlib 30 30 INCLUDES = -I../../lib -I../../packages/mg-1.3d -I../../packages/mg-1.3d/lib \ 31 -I../../packages/mg-1.3d/src/text 31 -I../../packages/mg-1.3d/src/text -I../../packages/fcgi/include 32 32 LDFLAGS = -lg++ -lgdbm 33 33 LIBS = ../../lib/gsdllib.a -
trunk/gsdl/src/library/cgiwrap.cpp
r89 r90 18 18 #include "fileutil.h" 19 19 20 #ifdef USE_FASTCGI 21 #include "fcgiapp.h" 22 #endif 23 20 24 // Note: site.h would not be needed if we could 21 25 // dynamically find out gsdlhome. … … 23 27 24 28 25 static void site_cfg_read (libinterface *lib, const text_t &filename) { 29 #ifdef USE_FASTCGI 30 // used to output the text from libinterface 31 class fcgistreambuf : public streambuf { 32 public: 33 fcgistreambuf (); 34 int sync (); 35 int overflow (int ch); 36 int underflow () {return EOF;} 37 38 void fcgisbreset() {fcgx_stream = NULL; other_ostream = NULL;}; 39 void set_fcgx_stream(FCGX_Stream *newone) {fcgx_stream=newone;}; 40 void set_other_ostream(ostream *newone) {other_ostream=newone;}; 41 42 private: 43 FCGX_Stream *fcgx_stream; 44 ostream *other_ostream; 45 }; 46 47 fcgistreambuf::fcgistreambuf() { 48 fcgisbreset(); 49 if (base() == ebuf()) allocate(); 50 setp (base(), ebuf()); 51 }; 52 53 int fcgistreambuf::sync () { 54 if ((fcgx_stream != NULL) && 55 (FCGX_PutStr (pbase(), out_waiting(), fcgx_stream) < 0)) { 56 fcgx_stream = NULL; 57 } 58 59 if (other_ostream != NULL) { 60 char *thepbase=pbase(); 61 for (int i=0;i<out_waiting();i++) (*other_ostream).put(thepbase[i]); 62 } 63 64 setp (pbase(), epptr()); 65 66 return 0; 67 } 68 69 int fcgistreambuf::overflow (int ch) { 70 if (sync () == EOF) return EOF; 71 if (ch != EOF) sputc (ch); 72 return 0; 73 } 74 75 #endif 76 77 78 79 static int site_cfg_read (libinterface *lib, const text_t &filename, 80 int &maxrequests) { 26 81 text_tarray cfgline; 27 82 char *cstr = filename.getcstr(); 28 83 ifstream confin (cstr); 29 84 delete cstr; 85 86 maxrequests = 10000; 30 87 31 88 if (confin) { … … 38 95 else if (cfgline[0] == "httpprefix") lib->sethttpprefix(cfgline[1]); 39 96 else if (cfgline[0] == "gwcgi") lib->setgwcgi(cfgline[1]); 97 else if (cfgline[0] == "maxrequests") { 98 maxrequests = cfgline[1].getint(); 99 if (maxrequests < 1) maxrequests = 1; 100 } 40 101 } 41 102 } 42 103 confin.close (); 43 } 104 return 1; 105 } 106 return 0; 44 107 } 45 108 46 109 // cgiwrap does everything necessary to output a page 47 // using the cgi protocol.110 // using the cgi (or fastcgi) protocol. 48 111 int cgiwrap (libinterface *lib) { 112 #ifdef USE_FASTCGI 113 fcgistreambuf outbuf; 114 #endif 115 116 // init stuff 117 49 118 // set defaults 119 int maxrequests = 10000; 50 120 lib->setgsdlhome (GSDLHOME); 51 121 lib->sethttpprefix("http://127.0.0.1"); 52 122 lib->setgwcgi("http://127.0.0.1/cgi-bin/gw"); 53 123 54 // read in the main configuration file 55 text_t filename = filename_cat (GSDLHOME, "etc/site.cfg"); 56 site_cfg_read (lib, filename); 57 58 // read in the collection configuration file (overriding the 59 // main configuration file) 60 filename = filename_cat (GSDLHOME, "collect"); 124 // read in the site configuration file 125 // try in the collection directory, then GSDLHOME/etc, 126 // then in GSDLHOME. 127 text_t filename = filename_cat (GSDLHOME, "collect"); 61 128 filename = filename_cat (filename, lib->get_collection_name()); 62 129 filename = filename_cat (filename, "site.cfg"); 63 site_cfg_read (lib, filename); 130 if (!site_cfg_read (lib, filename, maxrequests)) { 131 filename = filename_cat (GSDLHOME, "etc/site.cfg"); 132 if (!site_cfg_read (lib, filename, maxrequests)) { 133 filename = filename_cat (GSDLHOME, "site.cfg"); 134 site_cfg_read (lib, filename, maxrequests); 135 } 136 } 64 137 65 138 // initialise the library software 66 139 lib->init(); 67 140 68 // get the query arguments from the environment 69 // or from standard input 141 // find out whether this is being run as a cgi-script 142 // or a fastcgi script 143 int numrequests = 0; 144 #ifdef USE_FASTCGI 145 int isfastcgi = !FCGX_IsCGI(); 146 FCGX_Stream *fcgiin, *fcgiout, *fcgierr; 147 FCGX_ParamArray fcgienvp; 148 #else 149 int isfastcgi = 0; 150 #endif 151 152 // get the query string if it is not being run as a fastcgi 153 // script 70 154 text_t argstr = ""; 71 char *aURIStr = getenv("QUERY_STRING"); 72 if (aURIStr != NULL) { 73 // the arguments were available in the environment 74 argstr = aURIStr; 75 } else { 76 // get the arguments from standard input 77 char cinURIStr[1024]; 78 cin >> cinURIStr; 79 argstr = cinURIStr; 80 } 81 82 // output the cgi header 83 cout << "content-type: text/html\n\n"; 84 85 // redirect stderr to a file 86 ofstream errout (GSDLHOME "/etc/errout.txt"); 87 cerr = errout; 88 89 // get the query page 90 lib->getpage (argstr, cout, errout); 91 92 // close the file containing the redirected standard output 93 errout.close(); 94 95 // make sure we finish with a return on an empty line 96 cout << "\n"; 155 char *aURIStr; 156 if (!isfastcgi) { 157 aURIStr = getenv("QUERY_STRING"); 158 if (aURIStr != NULL) argstr = aURIStr; 159 else { 160 char cinURIStr[1024]; 161 cin >> cinURIStr; 162 argstr = cinURIStr; 163 } 164 maxrequests = 1; 165 } 166 167 // Page-request loop. If this is not being run as a fastcgi 168 // process then only one request will be processed and then 169 // the process will exit. 170 while (numrequests < maxrequests) { 171 #ifdef USE_FASTCGI 172 if (isfastcgi) { 173 if (FCGX_Accept(&fcgiin, &fcgiout, &fcgierr, &fcgienvp) < 0) break; 174 aURIStr = FCGX_GetParam("QUERY_STRING", fcgienvp); 175 if (aURIStr != NULL) argstr = aURIStr; 176 else argstr = ""; 177 } 178 #endif 179 180 // get output streams ready 181 #ifdef USE_FASTCGI 182 outbuf.fcgisbreset (); 183 if (isfastcgi) outbuf.set_fcgx_stream (fcgiout); 184 else outbuf.set_other_ostream (&cout); 185 ostream pageout (&outbuf); 186 #else 187 #define pageout cout 188 #endif 189 pageout << "content-type: text/html\n\n"; 190 ofstream errout (GSDLHOME "/etc/errout.txt"); 191 cerr = errout; 192 193 // get the query page 194 lib->getpage (argstr, pageout, errout); 195 196 // finish with the output streams 197 pageout << "\n"; 198 pageout << flush; 199 errout.close(); 200 #ifdef USE_FASTCGI 201 if (isfastcgi) FCGX_Finish(); 202 #endif 203 204 numrequests++; 205 } 97 206 98 207 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.