|
|
| version 1.108, 2001/09/04 19:05:04 | version 1.117, 2001/10/08 09:04:08 |
|---|---|
| Line 2 | Line 2 |
| Parser: scripting and CGI main. | Parser: scripting and CGI main. |
| Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) | Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru>(http://design.ru/paf) |
| $Id$ | |
| */ | */ |
| static const char *RCSId="$Id$"; | |
| #include "pa_config_includes.h" | #include "pa_config_includes.h" |
| Line 22 static const char *RCSId="$Id$"; | Line 22 static const char *RCSId="$Id$"; |
| //#define DEBUG_POOL_MALLOC | //#define DEBUG_POOL_MALLOC |
| // consts | |
| extern const char *main_RCSIds[]; | |
| #ifdef USE_SMTP | |
| extern const char *smtp_RCSIds[]; | |
| #endif | |
| extern const char *gd_RCSIds[]; | |
| extern const char *classes_RCSIds[]; | |
| extern const char *types_RCSIds[]; | |
| extern const char *parser3_RCSIds[]; | |
| const char **RCSIds[]={ | |
| main_RCSIds, | |
| #ifdef USE_SMTP | |
| smtp_RCSIds, | |
| #endif | |
| gd_RCSIds, | |
| classes_RCSIds, | |
| types_RCSIds, | |
| parser3_RCSIds, | |
| 0 | |
| }; | |
| /// IIS refuses to read bigger chunks | /// IIS refuses to read bigger chunks |
| const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M | const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M |
| Line 76 void SAPI::log(Pool& pool, const char *f | Line 97 void SAPI::log(Pool& pool, const char *f |
| // message | // message |
| va_list args; | va_list args; |
| va_start(args,fmt); | va_start(args,fmt); |
| vfprintf(f, fmt, args); | |
| char buf[MAX_STRING]; | |
| size_t size=vsnprintf(buf, MAX_STRING, fmt, args); | |
| remove_crlf(buf, buf+size); | |
| fwrite(buf, size, 1, f); | |
| va_end(args); | va_end(args); |
| // newline | // newline |
| fprintf(f, "\n"); | fprintf(f, "\n"); |
| Line 87 void SAPI::log(Pool& pool, const char *f | Line 113 void SAPI::log(Pool& pool, const char *f |
| fflush(f); | fflush(f); |
| } | } |
| static char *_getenv(const char *name) { | |
| char *result=getenv(name); | |
| return result && *result ? result : 0; | |
| } | |
| const char *SAPI::get_env(Pool& pool, const char *name) { | const char *SAPI::get_env(Pool& pool, const char *name) { |
| return _getenv(name); | return getenv(name); |
| } | } |
| size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { | size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { |
| Line 149 char *full_file_spec(char *file_name) { | Line 170 char *full_file_spec(char *file_name) { |
| wich is tested but seems slow. | wich is tested but seems slow. |
| */ | */ |
| int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { |
| int result; | |
| argv0=argv[0]; | argv0=argv[0]; |
| umask(2); | umask(2); |
| // were we started as CGI? | // were we started as CGI? |
| cgi= | cgi= |
| _getenv("SERVER_SOFTWARE") || | getenv("SERVER_SOFTWARE") || |
| _getenv("SERVER_NAME") || | getenv("SERVER_NAME") || |
| _getenv("GATEWAY_INTERFACE") || | getenv("GATEWAY_INTERFACE") || |
| _getenv("REQUEST_METHOD"); | getenv("REQUEST_METHOD"); |
| if(!cgi) { | if(!cgi) { |
| if(argc<2) { | if(argc<2) { |
| Line 179 int main(int argc, char *argv[]) { | Line 201 int main(int argc, char *argv[]) { |
| setmode(fileno(stderr), _O_BINARY); | setmode(fileno(stderr), _O_BINARY); |
| #endif | #endif |
| char *filespec_to_process=cgi?_getenv("PATH_TRANSLATED"):argv[1]; | char *filespec_to_process=cgi?getenv("PATH_TRANSLATED"):argv[1]; |
| #ifdef WIN32 | #ifdef WIN32 |
| back_slashes_to_slashes(filespec_to_process); | back_slashes_to_slashes(filespec_to_process); |
| #endif | #endif |
| filespec_to_process=full_file_spec(filespec_to_process); | filespec_to_process=full_file_spec(filespec_to_process); |
| const char *request_method=_getenv("REQUEST_METHOD"); | const char *request_method=getenv("REQUEST_METHOD"); |
| bool header_only=request_method && strcasecmp(request_method, "HEAD")==0; | bool header_only=request_method && strcasecmp(request_method, "HEAD")==0; |
| PTRY { // global try | PTRY { // global try |
| // must be first in PTRY{}PCATCH | // must be first in PTRY{}PCATCH |
| Line 278 int main(int argc, char *argv[]) { | Line 300 int main(int argc, char *argv[]) { |
| // some root-controlled location | // some root-controlled location |
| #ifdef SYSCONFDIR | #ifdef SYSCONFDIR |
| const char *root_auto_path=SYSCONFDIR; | const char *root_config_filespec=SYSCONFDIR "/" CONFIG_FILE_NAME; |
| #else | #else |
| # ifdef WIN32 | # ifdef WIN32 |
| // c:\windows | // c:\windows |
| static char root_auto_path[MAX_STRING]; | char root_config_path[MAX_STRING]; |
| GetWindowsDirectory(root_auto_path, MAX_STRING); | GetWindowsDirectory(root_config_path, MAX_STRING); |
| char root_config_filespec[MAX_STRING]; | |
| snprintf(root_config_filespec, MAX_STRING, | |
| "%s/%s", | |
| root_config_path, CONFIG_FILE_NAME); | |
| # else | # else |
| #error must be compiled either configure/make or MSVC++ | #error must be compiled either configure/make or MSVC++ |
| # endif | # endif |
| #endif | #endif |
| // beside by binary | // beside by binary |
| static char site_auto_path[MAX_STRING]; | // @todo full path, not ./! |
| strncpy(site_auto_path, argv0, MAX_STRING-1); site_auto_path[MAX_STRING-1]=0; // filespec of my binary | static char site_config_path[MAX_STRING]; |
| strncpy(site_config_path, argv0, MAX_STRING-1); site_config_path[MAX_STRING-1]=0; // filespec of my binary | |
| if(!( | if(!( |
| rsplit(site_auto_path, '/') || | rsplit(site_config_path, '/') || |
| rsplit(site_auto_path, '\\'))) { // strip filename | rsplit(site_config_path, '\\'))) { // strip filename |
| // no path, just filename | // no path, just filename |
| site_auto_path[0]='.'; site_auto_path[1]=0; | site_config_path[0]='.'; site_config_path[1]=0; |
| } | } |
| char site_config_filespec[MAX_STRING]; | |
| snprintf(site_config_filespec, MAX_STRING, | |
| "%s/%s", | |
| site_config_path, CONFIG_FILE_NAME); | |
| // process the request | // process the request |
| request.core( | request.core( |
| root_auto_path, false, | root_config_filespec, false, |
| site_auto_path, false, | site_config_filespec, false, |
| header_only); | header_only); |
| // | // |
| Line 318 int main(int argc, char *argv[]) { | Line 351 int main(int argc, char *argv[]) { |
| SetUnhandledExceptionFilter(0); | SetUnhandledExceptionFilter(0); |
| #endif | #endif |
| #ifndef WIN32 | |
| // | |
| if(!cgi) | |
| SAPI::send_body(pool, "\n", 1); | |
| #endif | |
| // successful finish | // successful finish |
| return 0; | result=0; |
| } PCATCH(e) { // global problem | } PCATCH(e) { // global problem |
| // must be first in PCATCH{} | // must be first in PCATCH{} |
| #ifdef WIN32 | #ifdef WIN32 |
| Line 355 int main(int argc, char *argv[]) { | Line 382 int main(int argc, char *argv[]) { |
| if(!header_only) | if(!header_only) |
| SAPI::send_body(pool, body, content_length); | SAPI::send_body(pool, body, content_length); |
| #ifndef WIN32 | |
| // | |
| if(!cgi) | |
| SAPI::send_body(pool, "\n", 1); | |
| #endif | |
| // unsuccessful finish | // unsuccessful finish |
| return 1; | result=1; |
| } | } |
| PEND_CATCH | PEND_CATCH |
| #ifndef WIN32 | |
| // | |
| if(!cgi) | |
| SAPI::send_body(pool, "\n", 1); | |
| #endif | |
| return result; | |
| } | } |