Annotation of parser3/src/targets/cgi/parser3.C, revision 1.216.2.13
1.27 paf 1: /** @file
2: Parser: scripting and CGI main.
3:
1.216.2.1 paf 4: Copyright(c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)
1.154 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.189 paf 6: */
1.27 paf 7:
1.216.2.13! paf 8: static const char* IDENT_PARSER3_C="$Date: 2003/02/21 10:11:14 $";
1.1 paf 9:
1.40 paf 10: #include "pa_config_includes.h"
1.3 paf 11:
1.139 paf 12: #if _MSC_VER
1.148 paf 13: # include <crtdbg.h>
1.3 paf 14: #endif
1.27 paf 15:
1.37 paf 16: #include "pa_sapi.h"
1.76 paf 17: #include "classes.h"
1.24 paf 18: #include "pa_common.h"
1.2 paf 19: #include "pa_request.h"
1.57 paf 20: #include "pa_socks.h"
1.68 paf 21: #include "pa_version.h"
1.207 paf 22:
1.149 paf 23: #ifdef WIN32
24: # include <windows.h>
1.184 paf 25: # include "getopt.h"
26: #else
27: # include <getopt.h>
1.120 parser 28: #endif
29:
1.158 paf 30: //#define DEBUG_POOL_MALLOC
1.196 paf 31: //#define DEBUG_MAILRECEIVE "mailreceive.eml"
1.160 paf 32:
1.109 parser 33: // consts
1.84 parser 34:
1.175 paf 35: #define REDIRECT_PREFIX "REDIRECT_"
1.181 paf 36: #define PARSER_CONFIG_ENV_NAME "CGI_PARSER_CONFIG"
1.159 paf 37:
1.42 paf 38: /// IIS refuses to read bigger chunks
39: const size_t READ_POST_CHUNK_SIZE=0x400*0x400; // 1M
40:
1.216.2.1 paf 41: static const char* argv0;
42: static const char* config_filespec_cstr=0;
1.193 paf 43: static bool fail_on_config_read_problem=true;
1.192 paf 44:
1.184 paf 45: static bool cgi; ///< we were started as CGI?
46: static bool mail_received=false; ///< we were started with -m option? [asked to parse incoming message to $mail:received]
1.5 paf 47:
1.201 paf 48: // for signal handlers
49: Request *request=0;
50:
1.46 paf 51: // SAPI
1.86 parser 52:
1.216.2.3 paf 53: class SAPI_Info{} SAPI_info;
54:
1.216.2.1 paf 55: static void log(const char* fmt, va_list args) {
1.193 paf 56: bool opened=false;
1.61 paf 57: FILE *f=0;
58:
1.193 paf 59: if(config_filespec_cstr) {
60: char beside_config_path[MAX_STRING];
61: strncpy(beside_config_path, config_filespec_cstr, MAX_STRING-1); beside_config_path[MAX_STRING-1]=0;
62: if(!(
63: rsplit(beside_config_path, '/') ||
64: rsplit(beside_config_path, '\\'))) { // strip filename
65: // no path, just filename
66: beside_config_path[0]='.'; beside_config_path[1]=0;
67: }
68:
69: char file_spec[MAX_STRING];
70: snprintf(file_spec, MAX_STRING,
71: "%s/parser3.log", beside_config_path);
72: f=fopen(file_spec, "at");
73: opened=f!=0;
74: }
1.192 paf 75: // fallback to stderr
1.61 paf 76: if(!opened)
77: f=stderr;
1.208 paf 78:
79: // use no memory [so that we could log out-of-memory error]
80: setbuf(f, 0); // stderr stream is unbuffered by default, but still...
1.61 paf 81:
82: // prefix
83: time_t t=time(0);
1.216.2.1 paf 84: if(const char* stamp=ctime(&t)) { // never saw that
1.173 paf 85: if(size_t len=strlen(stamp)) // saw once stamp being =""
1.172 paf 86: fprintf(f, "[%.*s] ", len-1, stamp);
1.171 paf 87: }
1.61 paf 88: // message
1.117 parser 89:
90: char buf[MAX_STRING];
91: size_t size=vsnprintf(buf, MAX_STRING, fmt, args);
92: remove_crlf(buf, buf+size);
93:
94: fwrite(buf, size, 1, f);
1.61 paf 95: // newline
96: fprintf(f, "\n");
97:
98: if(opened)
99: fclose(f);
1.85 parser 100: else
101: fflush(f);
1.124 parser 102: }
103:
104: // appends to parser3.log located beside my binary if openable, to stderr otherwize
1.216.2.3 paf 105: void SAPI::log(SAPI_Info&, const char* fmt, ...) {
1.124 parser 106: va_list args;
107: va_start(args,fmt);
108: ::log(fmt, args);
109: va_end(args);
110: }
111:
1.216.2.1 paf 112: void SAPI::die(const char* fmt, ...) {
1.216.2.11 paf 113: //_asm int 3;
1.137 paf 114: #ifdef DEBUG_POOL_MALLOC
115: extern void log_pool_stats(Pool& pool);
1.216.2.3 paf 116: log_pool_stats(SAPI_info);
1.137 paf 117: #endif
118:
1.144 paf 119: va_list args;
120: va_start(args,fmt);
1.138 paf 121: // log
122:
123: // logging is more important than user
1.204 paf 124: // she can cancel download, we'd get SIGPIPE,
1.138 paf 125: // nothing would be logged then
1.124 parser 126: ::log(fmt, args);
127:
1.138 paf 128: // inform user
129:
1.134 paf 130: char body[MAX_STRING];
1.138 paf 131: int content_length=vsnprintf(body, MAX_STRING, fmt, args);
1.134 paf 132:
1.144 paf 133: va_end(args);
134:
1.134 paf 135: // prepare header
136: // let's be honest, that's bad we couldn't produce valid output
1.216.2.3 paf 137: SAPI::add_header_attribute(SAPI_info, "status", "500");
138: SAPI::add_header_attribute(SAPI_info, "content-type", "text/plain");
1.134 paf 139: char content_length_cstr[MAX_NUMBER];
1.168 paf 140: snprintf(content_length_cstr, sizeof(content_length_cstr), "%u", content_length);
1.216.2.3 paf 141: SAPI::add_header_attribute(SAPI_info, "content-length", content_length_cstr);
1.134 paf 142:
143: // send header
1.216.2.3 paf 144: SAPI::send_header(SAPI_info);
1.134 paf 145:
146: // body
1.216.2.3 paf 147: SAPI::send_body(SAPI_info, body, content_length);
1.134 paf 148:
1.214 paf 149: #ifdef WIN32
1.216.2.11 paf 150: //_asm int 3;
1.214 paf 151: // IIS with abort failes to show STDOUT, it just barks "abnormal program termination"
152: exit(1);
153: #else
1.211 paf 154: // exit & try to produce core dump
155: abort();
1.214 paf 156: #endif
1.61 paf 157: }
158:
1.216.2.3 paf 159: CharPtr SAPI::get_env(SAPI_Info& , const char* name) {
160: if(char *local=getenv(name)) {
161: size_t size=strlen(local)+1;
162: char *heap=new char[size];
163: memcpy(heap, local, size);
164: return CharPtr(heap);
165: }
166: else
167: return CharPtr(0);
1.28 paf 168: }
169:
1.216.2.3 paf 170: const char* const *SAPI::environment(SAPI_Info&, Pool&) {
1.180 paf 171: #ifdef _MSC_VER
172: extern char **_environ;
173: return _environ;
174: #else
175: extern char **environ;
176: return environ;
177: #endif
178: }
179:
1.216.2.3 paf 180: size_t SAPI::read_post(SAPI_Info& , char *buf, size_t max_bytes) {
1.59 paf 181: size_t read_size=0;
1.12 paf 182: do {
1.200 paf 183: ssize_t chunk_size=read(fileno(stdin),
1.42 paf 184: buf+read_size, min(READ_POST_CHUNK_SIZE, max_bytes-read_size));
1.129 paf 185: if(chunk_size<=0)
1.12 paf 186: break;
187: read_size+=chunk_size;
188: } while(read_size<max_bytes);
189:
190: return read_size;
1.10 paf 191: }
192:
1.216.2.3 paf 193: void SAPI::add_header_attribute(SAPI_Info& , const char* dont_store_key, const char* dont_store_value) {
1.68 paf 194: if(cgi)
1.216.2.2 paf 195: printf("%s: %s\n", dont_store_key, dont_store_value);
1.19 paf 196: }
197:
1.56 paf 198: /// @todo intelligent cache-control
1.216.2.3 paf 199: void SAPI::send_header(SAPI_Info& ) {
1.33 paf 200: if(cgi) {
1.147 paf 201: // puts("expires: Fri, 23 Mar 2001 09:32:23 GMT");
1.33 paf 202:
203: // header | body delimiter
1.20 paf 204: puts("");
1.33 paf 205: }
1.30 paf 206: }
1.20 paf 207:
1.216.2.3 paf 208: void SAPI::send_body(SAPI_Info& , const void *buf, size_t size) {
1.19 paf 209: stdout_write(buf, size);
1.58 paf 210: }
211:
1.97 parser 212: //
213:
1.216.2.1 paf 214: static void full_file_spec(const char* file_name, char *buf, size_t buf_size) {
1.210 paf 215: if(file_name)
1.167 paf 216: if(file_name[0]=='/'
217: #ifdef WIN32
1.210 paf 218: || file_name[0] && file_name[1]==':'
1.167 paf 219: #endif
1.210 paf 220: )
1.167 paf 221: strncpy(buf, file_name, buf_size);
222: else {
223: char cwd[MAX_STRING]; getcwd(cwd, MAX_STRING);
224: snprintf(buf, buf_size, "%s/%s", cwd, file_name);
225: }
226: else
227: buf[0]=0;
1.166 paf 228: #ifdef WIN32
229: back_slashes_to_slashes(buf);
230: #endif
1.97 parser 231: }
232:
1.216.2.1 paf 233: static void log_signal(const char* signal_name) {
1.216.2.3 paf 234: SAPI::log(SAPI_info, request? "%s received. uri=%s, qs=%s"
1.205 paf 235: :"%s received. no request being processed",
236: signal_name,
1.216.2.3 paf 237: request && request->request_info.uri?request->request_info.uri:"-",
238: request && request->request_info.query_string?request->request_info.query_string:"-");
1.205 paf 239: }
240:
1.201 paf 241: #ifdef SIGUSR1
1.205 paf 242: static void SIGUSR1_handler(int /*sig*/){
243: log_signal("SIGUSR1");
1.201 paf 244: }
245: #endif
246:
247: #ifdef SIGPIPE
1.205 paf 248: static void SIGPIPE_handler(int /*sig*/){
249: log_signal("SIGPIPE");
1.201 paf 250: if(request)
251: request->interrupt();
252: }
253: #endif
254:
1.40 paf 255: /**
1.122 parser 256: main workhorse
1.19 paf 257:
1.122 parser 258: @todo
1.40 paf 259: IIS: remove trailing default-document[index.html] from $request.uri.
260: to do that we need to consult metabase,
261: wich is tested but seems slow.
1.144 paf 262: IIS5 todo find out proper 'illegal call' check
1.40 paf 263: */
1.184 paf 264: static void real_parser_handler(
1.216.2.1 paf 265: const char* filespec_to_process,
266: const char* request_method, bool header_only) {
1.122 parser 267: // init socks
1.216.2.3 paf 268: pa_init_socks();
1.122 parser 269:
270: // init global variables
1.216.2.3 paf 271: pa_globals_init();
1.122 parser 272:
1.198 paf 273: // request pool, must be different ptr from global [used in VStateless_class.add_method]
1.216.2.3 paf 274: Pool request_pool;
1.198 paf 275:
1.186 paf 276: if(!filespec_to_process || !*filespec_to_process)
1.144 paf 277: SAPI::die("Parser/%s", PARSER_VERSION);
1.122 parser 278:
279: // Request info
1.216.2.3 paf 280: Request_info request_info;
1.166 paf 281: char document_root_buf[MAX_STRING];
1.122 parser 282: if(cgi) {
1.216.2.3 paf 283: if(CharPtr env_document_root=SAPI::get_env(SAPI_info, "DOCUMENT_ROOT"))
1.122 parser 284: request_info.document_root=env_document_root;
1.216.2.3 paf 285: else if(const char* path_info=SAPI::get_env(SAPI_info, "PATH_INFO")) {
1.122 parser 286: // IIS
1.166 paf 287: size_t len=min(sizeof(document_root_buf)-1, strlen(filespec_to_process)-strlen(path_info));
288: memcpy(document_root_buf, filespec_to_process, len); document_root_buf[len]=0;
289: request_info.document_root=document_root_buf;
1.122 parser 290: } else
1.165 paf 291: throw Exception("parser.runtime",
1.216.2.3 paf 292: Exception::undefined_source,
1.165 paf 293: "CGI: no PATH_INFO defined(in reinventing DOCUMENT_ROOT)");
1.122 parser 294: } else {
1.166 paf 295: full_file_spec("", document_root_buf, sizeof(document_root_buf));
296: request_info.document_root=document_root_buf;
1.122 parser 297: }
298: request_info.path_translated=filespec_to_process;
299: request_info.method=request_method ? request_method : "GET";
1.216.2.10 paf 300: CharPtr query_string=SAPI::get_env(SAPI_info, "QUERY_STRING");
1.122 parser 301: request_info.query_string=query_string;
302: if(cgi) {
1.214 paf 303: // few absolute obligatory
1.216.2.3 paf 304: const char* path_info=SAPI::get_env(SAPI_info, "PATH_INFO");
1.214 paf 305: if(!path_info)
306: SAPI::die("CGI: illegal call (missing PATH_INFO)");
1.216.2.3 paf 307: const char* script_name=SAPI::get_env(SAPI_info, "SCRIPT_NAME");
1.214 paf 308: if(!script_name)
309: SAPI::die("CGI: illegal call (missing SCRIPT_NAME)");
310:
1.216.2.3 paf 311: const char* env_request_uri=SAPI::get_env(SAPI_info, "REQUEST_URI");
1.214 paf 312: if(env_request_uri)
1.122 parser 313: request_info.uri=env_request_uri;
1.214 paf 314: else
1.122 parser 315: if(query_string) {
1.216.2.6 paf 316: char *reconstructed_uri=new(request_pool) char[
1.122 parser 317: strlen(path_info)+1/*'?'*/+
1.216.2.6 paf 318: strlen(query_string)+1/*0*/];
1.122 parser 319: strcpy(reconstructed_uri, path_info);
320: strcat(reconstructed_uri, "?");
321: strcat(reconstructed_uri, query_string);
322: request_info.uri=reconstructed_uri;
323: } else
324: request_info.uri=path_info;
1.214 paf 325:
326: if(env_request_uri) { // apache & others stuck to standards
327: /*
328: http://parser3/env.html?123 =OK
329: $request:uri=/env.html?123
330: REQUEST_URI='/env.html?123'
331: SCRIPT_NAME='/cgi-bin/parser3'
332: PATH_INFO='/env.html'
333:
334: http://parser3/cgi-bin/parser3/env.html?123 =ERROR
335: $request:uri=/cgi-bin/parser3/env.html?123
336: REQUEST_URI='/cgi-bin/parser3/env.html?123'
337: SCRIPT_NAME='/cgi-bin/parser3'
338: PATH_INFO='/env.html'
339: */
340: size_t script_name_len=strlen(script_name);
341: size_t uri_len=strlen(env_request_uri);
342: if(strncmp(env_request_uri, script_name, script_name_len)==0 &&
343: script_name_len != uri_len) // under IIS they are the same
344: SAPI::die("CGI: illegal call (1)");
345: } else { // seen on IIS5
346: /*
347: http://nestle/env.html?123 =OK
348: $request:uri=/env.html?123
349: REQUEST_URI=''
350: SCRIPT_NAME='/env.html'
351: PATH_INFO='/env.html'
352:
353: http://nestle/cgi-bin/parser3.exe/env.html =ERROR
354: $request:uri=/env.html
355: REQUEST_URI=''
356: SCRIPT_NAME='/cgi-bin/parser3.exe'
357: PATH_INFO='/env.html'
358: */
359: if(strcmp(script_name, path_info)!=0)
360: SAPI::die("CGI: illegal call (2)");
361: }
1.122 parser 362: } else
1.177 paf 363: request_info.uri="";
1.122 parser 364:
1.216.2.3 paf 365: request_info.content_type=SAPI::get_env(SAPI_info, "CONTENT_TYPE");
366: const char* content_length=SAPI::get_env(SAPI_info, "CONTENT_LENGTH");
1.122 parser 367: request_info.content_length=(content_length?atoi(content_length):0);
1.216.2.3 paf 368: request_info.cookie=SAPI::get_env(SAPI_info, "HTTP_COOKIE");
1.184 paf 369: request_info.mail_received=mail_received;
370:
1.198 paf 371:
1.122 parser 372: // prepare to process request
1.216.2.4 paf 373: Request request(request_pool, SAPI_info,
1.122 parser 374: request_info,
1.184 paf 375: /*#ifdef _DEBUG
1.143 paf 376: String::UL_HTML|String::UL_OPTIMIZE_BIT
1.184 paf 377: #else*/
1.143 paf 378: cgi ? String::UL_HTML|String::UL_OPTIMIZE_BIT : String::UL_AS_IS
1.184 paf 379: /*#endif*/
1.143 paf 380: ,
1.130 paf 381: true /* status_allowed */);
1.201 paf 382:
383: // get request ptr for signal handlers
384: ::request=&request;
385:
1.181 paf 386: char config_filespec_buf[MAX_STRING];
1.193 paf 387: if(!config_filespec_cstr) {
1.216.2.1 paf 388: const char* config_by_env=getenv(PARSER_CONFIG_ENV_NAME);
1.193 paf 389: if(!config_by_env)
390: config_by_env=getenv(REDIRECT_PREFIX PARSER_CONFIG_ENV_NAME);
391: if(config_by_env)
392: config_filespec_cstr=config_by_env;
393: else {
394: // beside by binary
395: char beside_binary_path[MAX_STRING];
396: strncpy(beside_binary_path, argv0, MAX_STRING-1); beside_binary_path[MAX_STRING-1]=0; // filespec of my binary
397: if(!(
398: rsplit(beside_binary_path, '/') ||
399: rsplit(beside_binary_path, '\\'))) { // strip filename
400: // no path, just filename
401: // @todo full path, not ./!
402: beside_binary_path[0]='.'; beside_binary_path[1]=0;
403: }
404: snprintf(config_filespec_buf, MAX_STRING,
405: "%s/%s",
406: beside_binary_path, AUTO_FILE_NAME);
407: config_filespec_cstr=config_filespec_buf;
1.197 paf 408: fail_on_config_read_problem=entry_exists(config_filespec_cstr);
1.193 paf 409: }
1.122 parser 410: }
411:
412: // process the request
413: request.core(
1.193 paf 414: config_filespec_cstr, fail_on_config_read_problem,
1.122 parser 415: header_only);
1.201 paf 416:
417: // no request [prevent signal handlers from accessing invalid memory]
418: ::request=0;
1.122 parser 419:
420: //
1.216.2.3 paf 421: pa_done_socks();
1.122 parser 422:
423: #ifdef DEBUG_POOL_MALLOC
424: extern void log_pool_stats(Pool& pool);
1.198 paf 425: log_pool_stats(request_pool);
1.122 parser 426: #endif
427: }
428:
1.216.2.13! paf 429: #if _MSC_VER && !defined(_DEBUG)
1.216.2.11 paf 430: # define PA_USE___TRY
431: struct Parser_executed {
432: bool with_system_exception;
433: LPEXCEPTION_POINTERS system_exception;
434: };
1.216.2.13! paf 435: #endif
1.216.2.11 paf 436:
437: static
438: #ifdef PA_USE___TRY
439: Parser_executed
440: #else
441: void
442: #endif
443: call_real_parser_handler__do_SEH_return_it(
1.216.2.1 paf 444: const char* filespec_to_process,
445: const char* request_method, bool header_only) {
1.216.2.11 paf 446: #ifdef PA_USE___TRY
447: Parser_executed result={false};
1.122 parser 448: __try {
449: #endif
450: real_parser_handler(
451: filespec_to_process,
452: request_method, header_only);
453:
1.216.2.11 paf 454: #ifdef PA_USE___TRY
1.122 parser 455: } __except (
1.216.2.11 paf 456: (result.system_exception=GetExceptionInformation()),
1.122 parser 457: EXCEPTION_EXECUTE_HANDLER) {
1.216.2.12 paf 458: //_asm int 3;
1.216.2.11 paf 459: result.with_system_exception=true;
460: }
461: return result;
462: #endif
463: }
464:
465: static void call_real_parser_handler__do_SEH(
466: const char* filespec_to_process,
467: const char* request_method, bool header_only) {
468: #ifdef PA_USE___TRY
469: Parser_executed executed=
470: #endif
471: call_real_parser_handler__do_SEH_return_it(filespec_to_process,
472: request_method, header_only);
473:
474: #ifdef PA_USE___TRY
475: if(executed.with_system_exception)
476: if(executed.system_exception)
477: if(_EXCEPTION_RECORD *er=executed.system_exception->ExceptionRecord)
478: throw Exception(Exception::undefined_type,
479: Exception::undefined_source,
1.165 paf 480: "Exception 0x%08X at 0x%08X", er->ExceptionCode, er->ExceptionAddress);
1.122 parser 481: else
1.216.2.11 paf 482: throw Exception(Exception::undefined_type,
483: Exception::undefined_source,
484: "Exception <no exception record>");
485: else
486: throw Exception(Exception::undefined_type,
487: Exception::undefined_source,
488: "Exception <no exception information>");
1.122 parser 489: #endif
490: }
491:
1.216.2.1 paf 492: static void usage(const char* program) {
1.188 paf 493: printf(
1.216.2.1 paf 494: "Parser/%s Copyright(c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com)\n"
1.184 paf 495: "Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)\n"
496: "\n"
497: "Usage: %s [options] file\n"
498: "Options are:\n"
1.185 paf 499: #ifdef WITH_MAILRECEIVE
1.193 paf 500: " -m Parse mail, put received letter to $mail:received\n"
1.184 paf 501: #endif
1.193 paf 502: " -f config_file Use this config file (/path/to/auto.p)\n"
503: " -h Display usage information (this message)\n"
1.184 paf 504: , PARSER_VERSION,
505: program);
506: exit(EINVAL);
507: }
508:
1.195 paf 509: int main(int argc, char *argv[]) {
1.203 paf 510: #ifdef SIGUSR1
1.205 paf 511: if(signal(SIGUSR1, SIGUSR1_handler)==SIG_ERR)
1.203 paf 512: SAPI::die("Can not set handler for SIGUSR1");
513: #endif
514: #ifdef SIGPIPE
1.205 paf 515: if(signal(SIGPIPE, SIGPIPE_handler)==SIG_ERR)
1.203 paf 516: SAPI::die("Can not set handler for SIGPIPE");
517: #endif
518:
519:
1.185 paf 520: #ifdef DEBUG_MAILRECEIVE
521: if(FILE *fake_in=fopen(DEBUG_MAILRECEIVE, "rt")) {
1.184 paf 522: dup2(fake_in->_file, 0/*STDIN_FILENO*/);
523: }
524: #endif
525:
1.178 paf 526: #ifdef _DEBUG
1.216.2.9 paf 527: //_crtBreakAlloc=4042;
1.178 paf 528: #endif
1.216.2.10 paf 529: //_asm int 3;
1.193 paf 530: argv0=argv[0];
1.45 paf 531:
1.32 paf 532: umask(2);
533:
1.3 paf 534: // were we started as CGI?
1.146 paf 535: cgi=
1.109 parser 536: getenv("SERVER_SOFTWARE") ||
537: getenv("SERVER_NAME") ||
538: getenv("GATEWAY_INTERFACE") ||
539: getenv("REQUEST_METHOD");
1.5 paf 540:
1.184 paf 541: char *raw_filespec_to_process;
1.210 paf 542: if(cgi) {
1.184 paf 543: raw_filespec_to_process=getenv("PATH_TRANSLATED");
1.210 paf 544: if(raw_filespec_to_process && !*raw_filespec_to_process)
545: raw_filespec_to_process=0;
546: } else {
1.184 paf 547: optind = 1;
548: opterr = 0;
549: int c;
1.193 paf 550: while((c = getopt(argc, argv, "hf:"
1.185 paf 551: #ifdef WITH_MAILRECEIVE
1.184 paf 552: "m"
553: #endif
554: )) > 0) {
555: switch (c) {
556: case 'h':
557: usage(argv[0]);
1.193 paf 558: break;
559: case 'f':
560: config_filespec_cstr=optarg;
1.184 paf 561: break;
1.185 paf 562: #ifdef WITH_MAILRECEIVE
1.184 paf 563: case 'm':
564: mail_received=true;
565: break;
566: #endif
567: default:
568: fprintf(stderr, "%s: invalid option '%c'\n", argv[0], optopt);
569: usage(argv[0]);
570: break;
571: }
572: }
573: if (optind != argc - 1) {
574: fprintf(stderr, "%s: file not specified\n", argv[0]);
575: usage(argv[0]);
1.10 paf 576: }
1.184 paf 577:
578: raw_filespec_to_process=argv[optind++];
1.10 paf 579: }
580:
1.100 parser 581: #ifdef WIN32
582: setmode(fileno(stdin), _O_BINARY);
583: setmode(fileno(stdout), _O_BINARY);
584: setmode(fileno(stderr), _O_BINARY);
585: #endif
586:
1.139 paf 587: #if _MSC_VER
1.148 paf 588:
589: #ifdef _DEBUG
590: // Get current flag
591: int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
592:
593: // Turn on leak-checking bit
1.216.2.11 paf 594: // tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
1.148 paf 595:
596: // Set flag to the new value
597: _CrtSetDbgFlag( tmpFlag );
598: // _CrtSetBreakAlloc(471);
599:
600: #endif
601:
1.138 paf 602: #endif
603:
1.166 paf 604: char filespec_to_process[MAX_STRING];
605: full_file_spec(raw_filespec_to_process, filespec_to_process, sizeof(filespec_to_process));
1.10 paf 606:
1.216.2.1 paf 607: const char* request_method=getenv("REQUEST_METHOD");
1.35 paf 608: bool header_only=request_method && strcasecmp(request_method, "HEAD")==0;
1.131 paf 609:
1.122 parser 610: try { // global try
611: call_real_parser_handler__do_SEH(
612: filespec_to_process,
613: request_method, header_only);
614: } catch(const Exception& e) { // global problem
1.44 paf 615: // don't allocate anything on pool here:
616: // possible pool' exception not catch-ed now
617: // and there could be out-of-memory exception
1.43 paf 618:
1.144 paf 619: SAPI::die("exception in request exception handler: %s", e.comment());
1.16 paf 620: }
1.109 parser 621:
1.216.2.11 paf 622: // _asm int 3;
1.134 paf 623: return 0;
1.1 paf 624: }
E-mail: