--- parser3/src/targets/cgi/parser3.C 2001/08/27 13:27:26 1.97 +++ parser3/src/targets/cgi/parser3.C 2001/09/04 19:03:23 1.107 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: parser3.C,v 1.97 2001/08/27 13:27:26 parser Exp $"; +static const char *RCSId="$Id: parser3.C,v 1.107 2001/09/04 19:03:23 parser Exp $"; #include "pa_config_includes.h" @@ -60,7 +60,7 @@ void SAPI::log(Pool& pool, const char *f if(argv0) { // beside by binary char file_spec[MAX_STRING]; - strncpy(file_spec, argv0, MAX_STRING); // filespec of my binary + strncpy(file_spec, argv0, MAX_STRING-1); file_spec[MAX_STRING-1]=0; // filespec of my binary rsplit(file_spec, '/'); rsplit(file_spec, '\\');// strip filename strcat(file_spec, "/parser3.log"); f=fopen(file_spec, "at"); @@ -87,8 +87,13 @@ void SAPI::log(Pool& pool, const char *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) { - return getenv(name); + return _getenv(name); } size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { @@ -148,18 +153,12 @@ int main(int argc, char *argv[]) { umask(2); -#ifdef WIN32 - setmode(fileno(stdin), _O_BINARY); - setmode(fileno(stdout), _O_BINARY); - setmode(fileno(stderr), _O_BINARY); -#endif - // were we started as CGI? cgi= - getenv("SERVER_SOFTWARE") || - getenv("SERVER_NAME") || - getenv("GATEWAY_INTERFACE") || - getenv("REQUEST_METHOD"); + _getenv("SERVER_SOFTWARE") || + _getenv("SERVER_NAME") || + _getenv("GATEWAY_INTERFACE") || + _getenv("REQUEST_METHOD"); if(!cgi) { if(argc<2) { @@ -174,13 +173,19 @@ int main(int argc, char *argv[]) { } } - char *filespec_to_process=cgi?getenv("PATH_TRANSLATED"):argv[1]; +#ifdef WIN32 + setmode(fileno(stdin), _O_BINARY); + setmode(fileno(stdout), _O_BINARY); + setmode(fileno(stderr), _O_BINARY); +#endif + + char *filespec_to_process=cgi?_getenv("PATH_TRANSLATED"):argv[1]; #ifdef WIN32 back_slashes_to_slashes(filespec_to_process); #endif 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; PTRY { // global try // must be first in PTRY{}PCATCH @@ -210,8 +215,7 @@ int main(int argc, char *argv[]) { // IIS size_t len=strlen(filespec_to_process)-strlen(path_info); char *buf=(char *)pool.malloc(len+1); - strncpy(buf, filespec_to_process, len); - buf[len]=0; + memcpy(buf, filespec_to_process, len); buf[len]=0; request_info.document_root=buf; } else PTHROW(0, 0, @@ -219,14 +223,14 @@ int main(int argc, char *argv[]) { "CGI: no PATH_INFO defined(in reinventing DOCUMENT_ROOT)"); } else { static char buf[MAX_STRING]; - strncpy(buf, filespec_to_process, MAX_STRING); + strncpy(buf, filespec_to_process, MAX_STRING-1); buf[MAX_STRING-1]=0; if(rsplit(buf, '/') || rsplit(buf, '\\')) // strip filename request_info.document_root=buf; else request_info.document_root=""; } request_info.path_translated=filespec_to_process; - request_info.method=request_method; + request_info.method=request_method ? request_method : "GET"; const char *query_string=SAPI::get_env(pool, "QUERY_STRING"); request_info.query_string=query_string; if(cgi) { @@ -273,18 +277,21 @@ int main(int argc, char *argv[]) { ); // some root-controlled location -#ifdef WIN32 +#ifdef SYSCONFDIR + const char *root_auto_path=SYSCONFDIR; +#else +# ifdef WIN32 // c:\windows static char root_auto_path[MAX_STRING]; GetWindowsDirectory(root_auto_path, MAX_STRING); -#else - // ~nobody todo: figure out a better place - const char *root_auto_path=SAPI::get_env(pool, "HOME"); +# else + #error must be compiled either configure/make or MSVC++ +# endif #endif // beside by binary static char site_auto_path[MAX_STRING]; - strncpy(site_auto_path, argv0, MAX_STRING); // filespec of my binary + strncpy(site_auto_path, argv0, MAX_STRING-1); site_auto_path[MAX_STRING-1]=0; // filespec of my binary if(!( rsplit(site_auto_path, '/') || rsplit(site_auto_path, '\\'))) { // strip filename @@ -310,9 +317,12 @@ int main(int argc, char *argv[]) { #ifdef WIN32 SetUnhandledExceptionFilter(0); #endif + +#ifndef WIN32 // if(!cgi) SAPI::send_body(pool, "\n", 1); +#endif // successful finish return 0; @@ -345,9 +355,11 @@ int main(int argc, char *argv[]) { if(!header_only) SAPI::send_body(pool, body, content_length); +#ifndef WIN32 // if(!cgi) SAPI::send_body(pool, "\n", 1); +#endif // unsuccessful finish return 1;