|
|
| version 1.209, 2002/12/05 10:43:23 | version 1.213.2.1, 2002/12/17 12:45:40 |
|---|---|
| Line 157 void SAPI::die(const char *fmt, ...) { | Line 157 void SAPI::die(const char *fmt, ...) { |
| // body | // body |
| SAPI::send_body(global_pool, body, content_length); | SAPI::send_body(global_pool, body, content_length); |
| #ifdef WIN32 | |
| // IIS with abort failes to show STDOUT, it just barks "abnormal program termination" | |
| exit(1); | exit(1); |
| #else | |
| // exit & try to produce core dump | |
| abort(); | |
| #endif | |
| } | } |
| const char *SAPI::get_env(Pool& , const char *name) { | const char *SAPI::get_env(Pool& , const char *name) { |
| Line 209 void SAPI::send_body(Pool& , const void | Line 215 void SAPI::send_body(Pool& , const void |
| // | // |
| static void full_file_spec(const char *file_name, char *buf, size_t buf_size) { | static void full_file_spec(const char *file_name, char *buf, size_t buf_size) { |
| if(file_name && *file_name) | if(file_name) |
| if(file_name[0]=='/' | if(file_name[0]=='/' |
| #ifdef WIN32 | #ifdef WIN32 |
| || file_name[1]==':' | || file_name[0] && file_name[1]==':' |
| #endif | #endif |
| ) | ) |
| strncpy(buf, file_name, buf_size); | strncpy(buf, file_name, buf_size); |
| else { | else { |
| char cwd[MAX_STRING]; getcwd(cwd, MAX_STRING); | char cwd[MAX_STRING]; getcwd(cwd, MAX_STRING); |
| Line 299 static void real_parser_handler( | Line 305 static void real_parser_handler( |
| const char *query_string=SAPI::get_env(request_pool, "QUERY_STRING"); | const char *query_string=SAPI::get_env(request_pool, "QUERY_STRING"); |
| request_info.query_string=query_string; | request_info.query_string=query_string; |
| if(cgi) { | if(cgi) { |
| if(const char *env_request_uri=SAPI::get_env(request_pool, "REQUEST_URI")) | // few absolute obligatory |
| const char *path_info=SAPI::get_env(request_pool, "PATH_INFO"); | |
| if(!path_info) | |
| SAPI::die("CGI: illegal call (missing PATH_INFO)"); | |
| const char *script_name=SAPI::get_env(request_pool, "SCRIPT_NAME"); | |
| if(!script_name) | |
| SAPI::die("CGI: illegal call (missing SCRIPT_NAME)"); | |
| const char *env_request_uri=SAPI::get_env(request_pool, "REQUEST_URI"); | |
| if(env_request_uri) | |
| request_info.uri=env_request_uri; | request_info.uri=env_request_uri; |
| else if(const char *path_info=SAPI::get_env(request_pool, "PATH_INFO")) | else |
| if(query_string) { | if(query_string) { |
| char *reconstructed_uri=(char *)request_pool.malloc( | char *reconstructed_uri=(char *)request_pool.malloc( |
| strlen(path_info)+1/*'?'*/+ | strlen(path_info)+1/*'?'*/+ |
| Line 312 static void real_parser_handler( | Line 327 static void real_parser_handler( |
| request_info.uri=reconstructed_uri; | request_info.uri=reconstructed_uri; |
| } else | } else |
| request_info.uri=path_info; | request_info.uri=path_info; |
| else | |
| throw Exception("parser.runtime", | if(env_request_uri) { // apache & others stuck to standards |
| 0, | /* |
| "CGI: no PATH_INFO defined(in reinventing REQUEST_URI)"); | http://parser3/env.html?123 =OK |
| $request:uri=/env.html?123 | |
| // they've changed this under IIS5. | REQUEST_URI='/env.html?123' |
| if(const char *script_name=SAPI::get_env(request_pool, "SCRIPT_NAME")) { | SCRIPT_NAME='/cgi-bin/parser3' |
| size_t script_name_len=strlen(script_name); | PATH_INFO='/env.html' |
| size_t uri_len=strlen(request_info.uri); | |
| if(strncmp(request_info.uri,script_name, script_name_len)==0 && | http://parser3/cgi-bin/parser3/env.html?123 =ERROR |
| script_name_len != uri_len) // under IIS they are the same | $request:uri=/cgi-bin/parser3/env.html?123 |
| SAPI::die("CGI: illegal call"); | REQUEST_URI='/cgi-bin/parser3/env.html?123' |
| } | SCRIPT_NAME='/cgi-bin/parser3' |
| PATH_INFO='/env.html' | |
| */ | |
| size_t script_name_len=strlen(script_name); | |
| size_t uri_len=strlen(env_request_uri); | |
| if(strncmp(env_request_uri, script_name, script_name_len)==0 && | |
| script_name_len != uri_len) // under IIS they are the same | |
| SAPI::die("CGI: illegal call (1)"); | |
| } else { // seen on IIS5 | |
| /* | |
| http://nestle/env.html?123 =OK | |
| $request:uri=/env.html?123 | |
| REQUEST_URI='' | |
| SCRIPT_NAME='/env.html' | |
| PATH_INFO='/env.html' | |
| http://nestle/cgi-bin/parser3.exe/env.html =ERROR | |
| $request:uri=/env.html | |
| REQUEST_URI='' | |
| SCRIPT_NAME='/cgi-bin/parser3.exe' | |
| PATH_INFO='/env.html' | |
| */ | |
| if(strcmp(script_name, path_info)!=0) | |
| SAPI::die("CGI: illegal call (2)"); | |
| } | |
| } else | } else |
| request_info.uri=""; | request_info.uri=""; |
| Line 494 int main(int argc, char *argv[]) { | Line 533 int main(int argc, char *argv[]) { |
| getenv("REQUEST_METHOD"); | getenv("REQUEST_METHOD"); |
| char *raw_filespec_to_process; | char *raw_filespec_to_process; |
| if(cgi) | if(cgi) { |
| raw_filespec_to_process=getenv("PATH_TRANSLATED"); | raw_filespec_to_process=getenv("PATH_TRANSLATED"); |
| else { | if(raw_filespec_to_process && !*raw_filespec_to_process) |
| raw_filespec_to_process=0; | |
| } else { | |
| optind = 1; | optind = 1; |
| opterr = 0; | opterr = 0; |
| int c; | int c; |
| Line 587 int main(int argc, char *argv[]) { | Line 628 int main(int argc, char *argv[]) { |
| if(!cgi) | if(!cgi) |
| SAPI::send_body(global_pool, "\n", 1); | SAPI::send_body(global_pool, "\n", 1); |
| #endif | #endif |
| //_asm int 3; | //_asm int 3; |
| return 0; | return 0; |
| } | } |