|
|
| version 1.328, 2020/12/15 13:08:17 | version 1.331, 2020/12/15 20:57:56 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: scripting and CGI main. | Parser: scripting and CGI main. |
| Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| Line 52 static bool mail_received = false; // -m | Line 52 static bool mail_received = false; // -m |
| static char* parser3_filespec = 0; // argv[0] | static char* parser3_filespec = 0; // argv[0] |
| static char** argv_extra = NULL; | static char** argv_extra = NULL; |
| // for signal handlers | |
| static THREAD_LOCAL Request *request=0; | |
| // for error logging | // for error logging |
| static THREAD_LOCAL Request_info request_info; // global for correct log() reporting | static THREAD_LOCAL Request_info request_info; // global for correct log() reporting |
| static const char* filespec_4log = NULL; // null only if system-wide auto.p used | static const char* filespec_4log = NULL; // null only if system-wide auto.p used |
| Line 309 static void config_handler(SAPI_Info &in | Line 306 static void config_handler(SAPI_Info &in |
| // prepare to process request | // prepare to process request |
| Request r(info, request_info, String::Language(String::L_HTML|String::L_OPTIMIZE_BIT)); | Request r(info, request_info, String::Language(String::L_HTML|String::L_OPTIMIZE_BIT)); |
| { | // only once |
| // initing ::request ptr for signal handlers | config_filespec = locate_config(config_filespec, parser3_filespec); |
| RequestController rc(&r); | // process main auto.p only |
| // only once | r.core(config_filespec, false, String::Empty); |
| config_filespec = locate_config(config_filespec, parser3_filespec); | |
| // process main auto.p only | |
| r.core(config_filespec, false, String::Empty); | |
| // clearing ::request in RequestController desctructor to prevent signal handlers from accessing invalid memory | |
| } | |
| } | } |
| static void connection_handler(SAPI_Info_HTTPD &info, HTTPD_Connection &connection) { | static void connection_handler(SAPI_Info_HTTPD &info, HTTPD_Connection &connection) { |
| try { | try { |
| memset(&request_info, 0, sizeof(request_info)); | |
| connection.read_header(); | connection.read_header(); |
| info.populate_env(); | info.populate_env(); |
| char document_root_buf[MAX_STRING]; | char document_root_buf[MAX_STRING]; |
| full_disk_path("", document_root_buf, sizeof(document_root_buf)); | full_disk_path("", document_root_buf, sizeof(document_root_buf)); |
| memset(&request_info, 0, sizeof(request_info)); | |
| request_info.document_root = document_root_buf; | request_info.document_root = document_root_buf; |
| request_info.path_translated = filespec_to_process; | request_info.path_translated = filespec_to_process; |
| request_info.method = connection.method(); | request_info.method = connection.method(); |
| Line 342 static void connection_handler(SAPI_Info | Line 335 static void connection_handler(SAPI_Info |
| // prepare to process request | // prepare to process request |
| Request r(info, request_info, String::Language(String::L_HTML|String::L_OPTIMIZE_BIT)); | Request r(info, request_info, String::Language(String::L_HTML|String::L_OPTIMIZE_BIT)); |
| { | // process the request |
| // initing ::request ptr for signal handlers | r.core(config_filespec, strcasecmp(request_info.method, "HEAD")==0, String("httpd-main")); |
| RequestController rc(&r); | |
| // process the request | |
| r.core(config_filespec, strcasecmp(request_info.method, "HEAD")==0, String("httpd-main")); | |
| // clearing ::request in RequestController desctructor to prevent signal handlers from accessing invalid memory | |
| } | |
| } catch(const Exception& e) { // exception in connection handling or unhandled exception | } catch(const Exception& e) { // exception in connection handling or unhandled exception |
| SAPI::log(info, "%s", e.comment()); | SAPI::log(info, "%s", e.comment()); |
| SAPI::send_error(info, e.comment(), info.exception_http_status(e.type())); | SAPI::send_error(info, e.comment(), info.exception_http_status(e.type())); |
| Line 390 static void httpd_mode() { | Line 378 static void httpd_mode() { |
| pid_t pid=1; | pid_t pid=1; |
| #endif | #endif |
| try { | try { |
| request_info.method=NULL; // wipe previous request for correct logging | |
| HTTPD_Connection connection; | HTTPD_Connection connection; |
| if(!connection.accept(sock, 5)) | if(!connection.accept(sock, 5)) |
| continue; | continue; |
| Line 571 static void call_real_parser_handler__su | Line 560 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-2017 Art. Lebedev Studio (http://www.artlebedev.com)\n" | "Copyright (c) 2001-2020 Art. Lebedev Studio (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" |