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