--- parser3/src/targets/cgi/parser3.C 2001/05/15 11:36:15 1.78 +++ parser3/src/targets/cgi/parser3.C 2001/08/28 10:30:29 1.98 @@ -4,9 +4,8 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: parser3.C,v 1.78 2001/05/15 11:36:15 parser Exp $ */ +static const char *RCSId="$Id: parser3.C,v 1.98 2001/08/28 10:30:29 parser Exp $"; #include "pa_config_includes.h" @@ -21,6 +20,9 @@ #include "pa_socks.h" #include "pa_version.h" +//#define DEBUG_POOL_MALLOC + + /// IIS refuses to read bigger chunks const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M @@ -49,7 +51,8 @@ static LONG WINAPI TopLevelExceptionFilt #endif // SAPI -// appends to parser3.log located beside my binary + +// appends to parser3.log located beside my binary if openable, to stderr otherwize void SAPI::log(Pool& pool, const char *fmt, ...) { bool opened; FILE *f=0; @@ -57,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"); @@ -80,6 +83,8 @@ void SAPI::log(Pool& pool, const char *f if(opened) fclose(f); + else + fflush(f); } const char *SAPI::get_env(Pool& pool, const char *name) { @@ -118,6 +123,18 @@ void SAPI::send_body(Pool& pool, const v stdout_write(buf, size); } +// + +char *full_file_spec(char *file_name) { + if(!strchr(file_name, '/')) { + static char cwd[MAX_STRING]; getcwd(cwd, MAX_STRING); + static char buf[MAX_STRING]; + snprintf(buf, MAX_STRING, "%s/%s", cwd, file_name); + return buf; + } + return file_name; +} + /** main workhorse @@ -161,6 +178,7 @@ int main(int argc, char *argv[]) { #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"); bool header_only=request_method && strcasecmp(request_method, "HEAD")==0; @@ -192,8 +210,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, @@ -201,7 +218,7 @@ 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 @@ -266,8 +283,13 @@ int main(int argc, char *argv[]) { // beside by binary static char site_auto_path[MAX_STRING]; - strncpy(site_auto_path, argv[0], MAX_STRING); // filespec of my binary - rsplit(site_auto_path, '/'); rsplit(site_auto_path, '\\');// strip filename + 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 + // no path, just filename + site_auto_path[0]='.'; site_auto_path[1]=0; + } // process the request request.core( @@ -278,13 +300,19 @@ int main(int argc, char *argv[]) { // done_socks(); +#ifdef DEBUG_POOL_MALLOC extern void log_pool_stats(Pool& pool); log_pool_stats(pool); +#endif // must be last in PTRY{}PCATCH #ifdef WIN32 SetUnhandledExceptionFilter(0); #endif + // + if(!cgi) + SAPI::send_body(pool, "\n", 1); + // successful finish return 0; } PCATCH(e) { // global problem @@ -316,6 +344,10 @@ int main(int argc, char *argv[]) { if(!header_only) SAPI::send_body(pool, body, content_length); + // + if(!cgi) + SAPI::send_body(pool, "\n", 1); + // unsuccessful finish return 1; }