|
|
| version 1.243, 2007/08/17 08:16:11 | version 1.249, 2009/03/09 21:33:24 |
|---|---|
| Line 22 static const char * const IDENT_PARSER3_ | Line 22 static const char * const IDENT_PARSER3_ |
| #ifdef WIN32 | #ifdef WIN32 |
| # include <windows.h> | # include <windows.h> |
| # include "getopt.h" | |
| #else | |
| # include <getopt.h> | |
| #endif | #endif |
| // defines | // defines |
| Line 51 static const char* argv0; | Line 48 static const char* argv0; |
| static const char* config_filespec_cstr=0; | static const char* config_filespec_cstr=0; |
| static bool fail_on_config_read_problem=true; | static bool fail_on_config_read_problem=true; |
| static int args_skip=1; | |
| static char** argv_all = NULL; | |
| static bool cgi; ///< we were started as CGI? | 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] | static bool mail_received=false; ///< we were started with -m option? [asked to parse incoming message to $mail:received] |
| Line 112 static void log(const char* fmt, va_list | Line 112 static void log(const char* fmt, va_list |
| } | } |
| // message | // message |
| char buf[MAX_STRING]; | char buf[MAX_LOG_STRING]; |
| size_t size=vsnprintf(buf, MAX_STRING, fmt, args); | size_t size=vsnprintf(buf, MAX_LOG_STRING, fmt, args); |
| remove_crlf(buf, buf+size); | size=remove_crlf(buf, buf+size); |
| fwrite(buf, size, 1, f); | fwrite(buf, size, 1, f); |
| if(request_info) | if(request_info) |
| Line 166 static void die_or_abort(const char* fmt | Line 166 static void die_or_abort(const char* fmt |
| // prepare header | // prepare header |
| // let's be honest, that's bad we couldn't produce valid output | // let's be honest, that's bad we couldn't produce valid output |
| SAPI::add_header_attribute(SAPI_info, "status", "500"); | SAPI::add_header_attribute(SAPI_info, "status", "500"); |
| SAPI::add_header_attribute(SAPI_info, "content-type", "text/plain"); | SAPI::add_header_attribute(SAPI_info, HTTP_CONTENT_TYPE, "text/plain"); |
| char content_length_cstr[MAX_NUMBER]; | char content_length_cstr[MAX_NUMBER]; |
| snprintf(content_length_cstr, sizeof(content_length_cstr), "%u", content_length); | snprintf(content_length_cstr, sizeof(content_length_cstr), "%u", content_length); |
| SAPI::add_header_attribute(SAPI_info, "content-length", content_length_cstr); | SAPI::add_header_attribute(SAPI_info, "content-length", content_length_cstr); |
| Line 304 static void SIGPIPE_handler(int /*sig*/) | Line 304 static void SIGPIPE_handler(int /*sig*/) |
| if(request) | if(request) |
| sigpipe=request->main_class.get_element(sigpipe_name, request->main_class, false); | sigpipe=request->main_class.get_element(sigpipe_name, request->main_class, false); |
| if(sigpipe && sigpipe->as_bool()) | if(sigpipe && sigpipe->as_bool()) |
| log_signal("SIGPIPE"); | log_signal(SIGPIPE_NAME); |
| execution_canceled=true; | execution_canceled=true; |
| if(request) | if(request) |
| Line 475 static void real_parser_handler(const ch | Line 475 static void real_parser_handler(const ch |
| request_info.cookie=getenv("HTTP_COOKIE"); | request_info.cookie=getenv("HTTP_COOKIE"); |
| request_info.mail_received=mail_received; | request_info.mail_received=mail_received; |
| request_info.argv=argv_all; | |
| request_info.args_skip=args_skip; | |
| // get request_info ptr for signal handlers | // get request_info ptr for signal handlers |
| ::request_info=&request_info; | ::request_info=&request_info; |
| if(execution_canceled) | if(execution_canceled) |
| Line 595 static void call_real_parser_handler__su | Line 598 static void call_real_parser_handler__su |
| static void usage(const char* program) { | static void usage(const char* program) { |
| printf( | printf( |
| "Parser/%s\n" | "Parser/%s\n" |
| "Copyright(c) 2001-2007 ArtLebedev Group (http://www.artlebedev.com)\n" | "Copyright(c) 2001-2008 ArtLebedev Group (http://www.artlebedev.com)\n" |
| "Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)\n" | "Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)\n" |
| "\n" | "\n" |
| "Usage: %s [options] file\n" | "Usage: %s [options] file\n" |
| Line 654 int main(int argc, char *argv[]) { | Line 657 int main(int argc, char *argv[]) { |
| #ifdef _DEBUG | #ifdef _DEBUG |
| //_crtBreakAlloc=46; | //_crtBreakAlloc=46; |
| #endif | #endif |
| argv_all=argv; | |
| argv0=argv[0]; | argv0=argv[0]; |
| umask(2); | umask(2); |
| Line 671 int main(int argc, char *argv[]) { | Line 675 int main(int argc, char *argv[]) { |
| if(raw_filespec_to_process && !*raw_filespec_to_process) | if(raw_filespec_to_process && !*raw_filespec_to_process) |
| raw_filespec_to_process=0; | raw_filespec_to_process=0; |
| } else { | } else { |
| optind = 1; | size_t optind=1; |
| opterr = 0; | while(optind < argc){ |
| int c; | char *carg = argv[optind]; |
| while((c = getopt(argc, argv, "hf:" | if(carg[0] != '-') |
| #ifdef WITH_MAILRECEIVE | |
| "m" | |
| #endif | |
| )) > 0) { | |
| switch (c) { | |
| case 'h': | |
| usage(argv[0]); | |
| break; | |
| case 'f': | |
| config_filespec_cstr=optarg; | |
| break; | break; |
| for(size_t k = 1; k < strlen(carg); k++){ | |
| char c = carg[k]; | |
| switch (c) { | |
| case 'h': | |
| usage(argv[0]); | |
| break; | |
| case 'f': | |
| if(optind < argc - 1){ | |
| optind++; | |
| config_filespec_cstr=argv[optind]; | |
| } | |
| break; | |
| #ifdef WITH_MAILRECEIVE | #ifdef WITH_MAILRECEIVE |
| case 'm': | case 'm': |
| mail_received=true; | mail_received=true; |
| break; | break; |
| #endif | #endif |
| default: | default: |
| fprintf(stderr, "%s: invalid option '%c'\n", argv[0], optopt); | fprintf(stderr, "%s: invalid option '%c'\n", argv[0], c); |
| usage(argv[0]); | usage(argv[0]); |
| break; | break; |
| } | |
| } | } |
| optind++; | |
| } | } |
| if (optind != argc - 1) { | |
| if (optind > argc - 1) { | |
| fprintf(stderr, "%s: file not specified\n", argv[0]); | fprintf(stderr, "%s: file not specified\n", argv[0]); |
| usage(argv[0]); | usage(argv[0]); |
| } | } |
| raw_filespec_to_process=argv[optind]; | |
| raw_filespec_to_process=argv[optind++]; | args_skip=optind; |
| } | } |
| #ifdef WIN32 | #ifdef WIN32 |
| Line 754 int main(int argc, char *argv[]) { | Line 764 int main(int argc, char *argv[]) { |
| int content_length=strlen(buf); | int content_length=strlen(buf); |
| // prepare header | // prepare header |
| SAPI::add_header_attribute(SAPI_info, "content-type", "text/plain"); | SAPI::add_header_attribute(SAPI_info, HTTP_CONTENT_TYPE, "text/plain"); |
| char content_length_cstr[MAX_NUMBER]; | char content_length_cstr[MAX_NUMBER]; |
| snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length); | snprintf(content_length_cstr, MAX_NUMBER, "%u", content_length); |
| SAPI::add_header_attribute(SAPI_info, "content-length", content_length_cstr); | SAPI::add_header_attribute(SAPI_info, "content-length", content_length_cstr); |