--- parser3/src/targets/cgi/parser3.C 2002/06/24 14:47:53 1.185 +++ parser3/src/targets/cgi/parser3.C 2002/08/14 09:20:53 1.192 @@ -3,10 +3,10 @@ Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: parser3.C,v 1.185 2002/06/24 14:47:53 paf Exp $ */ +static const char* IDENT_PARSER3_C="$Date: 2002/08/14 09:20:53 $"; + #include "pa_config_includes.h" #if _MSC_VER @@ -31,7 +31,7 @@ //#define DEBUG_POOL_MALLOC //#define DEBUG_STRING_APPENDS_VS_EXPANDS -//#define DEBUG_MAILRECEIVE "test2.eml" +//#define DEBUG_MAILRECEIVE "test.eml" #ifdef DEBUG_STRING_APPENDS_VS_EXPANDS extern ulong @@ -43,28 +43,6 @@ extern ulong // consts -#ifndef _PROFILE -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 -}; -#endif - #define REDIRECT_PREFIX "REDIRECT_" #define PARSER_CONFIG_ENV_NAME "CGI_PARSER_CONFIG" @@ -72,6 +50,8 @@ const char **RCSIds[]={ const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M static const char *argv0; +static char beside_binary_path[MAX_STRING]; + static Pool *pool; // global pool [dont describe to doxygen: it confuses it with param names] static bool cgi; ///< we were started as CGI? static bool mail_received=false; ///< we were started with -m option? [asked to parse incoming message to $mail:received] @@ -82,15 +62,13 @@ static void log(const char *fmt, va_list bool opened; FILE *f=0; - if(argv0) { - // beside by binary - char file_spec[MAX_STRING]; - 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"); - } + // try beside by binary first + char file_spec[MAX_STRING]; + snprintf(file_spec, MAX_STRING, + "%s/parser3.log", beside_binary_path); + f=fopen(file_spec, "at"); opened=f!=0; + // fallback to stderr if(!opened) f=stderr; @@ -250,7 +228,7 @@ static void real_parser_handler( // init global variables pa_globals_init(*pool); - if(!filespec_to_process) + if(!filespec_to_process || !*filespec_to_process) SAPI::die("Parser/%s", PARSER_VERSION); // Request info @@ -333,16 +311,6 @@ static void real_parser_handler( if(config_by_env) config_filespec_cstr=config_by_env; else { - // beside by binary - // @todo full path, not ./! - char beside_binary_path[MAX_STRING]; - strncpy(beside_binary_path, argv0, MAX_STRING-1); beside_binary_path[MAX_STRING-1]=0; // filespec of my binary - if(!( - rsplit(beside_binary_path, '/') || - rsplit(beside_binary_path, '\\'))) { // strip filename - // no path, just filename - beside_binary_path[0]='.'; beside_binary_path[1]=0; - } snprintf(config_filespec_buf, MAX_STRING, "%s/%s", beside_binary_path, AUTO_FILE_NAME); @@ -416,7 +384,7 @@ static void failed_new() { #endif static void usage(const char *program) { - fprintf(stderr, + printf( "Parser/%s Copyright(c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)\n" "Author: Alexandr Petrosian (http://paf.design.ru)\n" "\n" @@ -446,7 +414,18 @@ int main(int argc, char *argv[]) { // _crtBreakAlloc=33112; #endif // _asm int 3; - argv0=argv[0]; + { + argv0=argv[0]; + // beside by binary + // @todo full path, not ./! + strncpy(beside_binary_path, argv0, MAX_STRING-1); beside_binary_path[MAX_STRING-1]=0; // filespec of my binary + if(!( + rsplit(beside_binary_path, '/') || + rsplit(beside_binary_path, '\\'))) { // strip filename + // no path, just filename + beside_binary_path[0]='.'; beside_binary_path[1]=0; + } + } umask(2);