|
|
| version 1.364, 2024/12/05 20:10:50 | version 1.366, 2024/12/11 18:35:31 |
|---|---|
| Line 52 SAPI_Info_CGI sapi_cgi; | Line 52 SAPI_Info_CGI sapi_cgi; |
| static SAPI_Info *sapi_info = &sapi_cgi; | static SAPI_Info *sapi_info = &sapi_cgi; |
| static THREAD_LOCAL SAPI_Info *sapi_info_4log = NULL; // global for correct send error in die() | static THREAD_LOCAL SAPI_Info *sapi_info_4log = NULL; // global for correct send error in die() |
| const char* parser3_mode = "cgi"; // $status:mode | |
| static const char* filespec_to_process = 0; // [file] | static const char* filespec_to_process = 0; // [file] |
| static const char* httpd_host_port = 0; // -p option | static const char* httpd_host_port = 0; // -p option |
| static const char* config_filespec = 0; // -f option or from env or next to the executable if exists | static const char* config_filespec = 0; // -f option or from env or next to the executable if exists |
| Line 73 template <typename T> static T *dir_pos( | Line 74 template <typename T> static T *dir_pos( |
| return result; | return result; |
| } | } |
| // SAPI | const char *parser3_log_filespec() { // $status:log-filename |
| static void pa_log(const char* fmt, va_list args) { | |
| FILE *f=0; | |
| const char* slog=log_filespec; | const char* slog=log_filespec; |
| if(!slog) | if(!slog) |
| slog=getenv(PARSER_LOG_ENV_NAME); | slog=getenv(PARSER_LOG_ENV_NAME); |
| if(!slog) | if(!slog) |
| slog=getenv(REDIRECT_PREFIX PARSER_LOG_ENV_NAME); | slog=getenv(REDIRECT_PREFIX PARSER_LOG_ENV_NAME); |
| if(!slog) { | |
| if(slog) { | static char log_spec[MAX_STRING + 12 /* '/parser3.log' */]; |
| f=strcmp(slog,"-") ? fopen(slog, "at") : stderr; | |
| } else if(filespec_4log) { | |
| char log_spec[MAX_STRING + 12 /* '/parser3.log' */]; | |
| pa_strncpy(log_spec, filespec_4log, MAX_STRING); | pa_strncpy(log_spec, filespec_4log, MAX_STRING); |
| if(char* log_dir_pos=dir_pos(log_spec)){ | if(char* log_dir_pos=dir_pos(log_spec)){ |
| Line 96 static void pa_log(const char* fmt, va_l | Line 91 static void pa_log(const char* fmt, va_l |
| // no path, just filename | // no path, just filename |
| strcpy(log_spec, "./parser3.log"); | strcpy(log_spec, "./parser3.log"); |
| } | } |
| f=fopen(log_spec, "at"); | slog=log_spec; |
| } | } |
| return slog; | |
| } | |
| // SAPI | |
| static void pa_log(const char* fmt, va_list args) { | |
| // use no memory [so that we could log out-of-memory error] | |
| const char* slog=parser3_log_filespec(); | |
| FILE *f=strcmp(slog,"-") ? fopen(slog, "at") : stderr; | |
| // fallback to stderr | // fallback to stderr |
| if(!f) | if(!f) |
| f=stderr; | f=stderr; |
| // use no memory [so that we could log out-of-memory error] | |
| setbuf(f, 0); // stderr stream is unbuffered by default, but still... | setbuf(f, 0); // stderr stream is unbuffered by default, but still... |
| // prefix | // prefix |
| Line 112 static void pa_log(const char* fmt, va_l | Line 115 static void pa_log(const char* fmt, va_l |
| if(size_t len=strlen(stamp)) // saw once stamp being ="" | if(size_t len=strlen(stamp)) // saw once stamp being ="" |
| fprintf(f, "[%.*s] [%u] ", (int)len-1, stamp, (unsigned int)pa_get_thread_id() ); | fprintf(f, "[%.*s] [%u] ", (int)len-1, stamp, (unsigned int)pa_get_thread_id() ); |
| } | } |
| // message | |
| // message | |
| char buf[MAX_LOG_STRING]; | char buf[MAX_LOG_STRING]; |
| size_t size=vsnprintf(buf, MAX_LOG_STRING, fmt, args); | size_t size=vsnprintf(buf, MAX_LOG_STRING, fmt, args); |
| size=remove_crlf(buf, buf+size); | size=remove_crlf(buf, buf+size); |
| Line 648 int main(int argc, char *argv[]) { | Line 651 int main(int argc, char *argv[]) { |
| // were we started as CGI? | // were we started as CGI? |
| bool cgi=(getenv("SERVER_SOFTWARE") || getenv("SERVER_NAME") || getenv("GATEWAY_INTERFACE") || getenv("REQUEST_METHOD")) && !getenv("PARSER_VERSION"); | bool cgi=(getenv("SERVER_SOFTWARE") || getenv("SERVER_NAME") || getenv("GATEWAY_INTERFACE") || getenv("REQUEST_METHOD")) && !getenv("PARSER_VERSION"); |
| if(!cgi) | if(!cgi){ |
| sapi_info = &sapi_console; | sapi_info = &sapi_console; |
| parser3_mode = "console"; | |
| } | |
| #ifdef SIGPIPE | #ifdef SIGPIPE |
| signal(SIGPIPE, SIGPIPE_handler); | signal(SIGPIPE, SIGPIPE_handler); |
| Line 680 int main(int argc, char *argv[]) { | Line 685 int main(int argc, char *argv[]) { |
| case 'p': | case 'p': |
| ARG_REQUIRED; | ARG_REQUIRED; |
| httpd_host_port=*carg; | httpd_host_port=*carg; |
| parser3_mode="httpd"; | |
| break; | break; |
| #ifdef WITH_MAILRECEIVE | #ifdef WITH_MAILRECEIVE |
| case 'm': | case 'm': |
| mail_received=true; | mail_received=true; |
| parser3_mode="mail"; | |
| break; | break; |
| #endif | #endif |
| default: | default: |