--- parser3/src/targets/cgi/parser3.C 2020/10/10 06:08:37 1.294 +++ parser3/src/targets/cgi/parser3.C 2020/10/11 23:25:10 1.296 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.294 2020/10/10 06:08:37 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.296 2020/10/11 23:25:10 moko Exp $"; #include "pa_config_includes.h" @@ -39,7 +39,7 @@ volatile const char * IDENT_PARSER3_C="$ #define PARSER_LOG_ENV_NAME "CGI_PARSER_LOG" static const char* config_filespec_cstr=0; // -f option -static const char* httpd_port=0; // -p option +static const char* httpd_host_port=0; // -p option static bool mail_received=false; // -m option? [asked to parse incoming message to $mail:received] static int args_skip=1; @@ -299,6 +299,7 @@ static bool locate_config(){ static void connection_handler(SAPI_Info_HTTPD &info, HTTPD_Connection &connection, const char* filespec_to_process){ connection.read_header(); + info.populate_env(); // Request info Request_info request_info; memset(&request_info, 0, sizeof(request_info)); @@ -308,12 +309,12 @@ static void connection_handler(SAPI_Info request_info.document_root = document_root_buf; request_info.path_translated = filespec_to_process; request_info.method = connection.method(); - request_info.query_string=NULL; - request_info.uri=request_info.strip_absolute_uri(connection.uri()); - request_info.content_type=connection.content_type(); - request_info.content_length=connection.content_length(); - request_info.cookie=info.get_env("HTTP_COOKIE"); - request_info.mail_received=false; + request_info.query_string = connection.query(); + request_info.uri = request_info.strip_absolute_uri(connection.uri()); + request_info.content_type = connection.content_type(); + request_info.content_length = connection.content_length(); + request_info.cookie = info.get_env("HTTP_COOKIE"); + request_info.mail_received = false; request_info.argv = argv_all + args_skip; // prepare to process request @@ -329,7 +330,7 @@ static void connection_handler(SAPI_Info } static void httpd_mode(const char* filespec_to_process){ - int sock = HTTPD_Server::bind(/*"127.0.0.1"*/ NULL, pa_atoui(httpd_port, 10)); + int sock = HTTPD_Server::bind(httpd_host_port); while(1 == 1){ HTTPD_Connection *connection = HTTPD_Server::accept(sock,5); @@ -354,7 +355,7 @@ static void real_parser_handler(const ch // init libraries pa_globals_init(); - if(httpd_port){ + if(httpd_host_port){ httpd_mode(filespec_to_process); } @@ -513,7 +514,7 @@ static void usage(const char* program) { " -m Parse mail, put received letter to $mail:received\n" #endif " -f config_file Use this config file (/path/to/auto.p)\n" - " -p port Start web server on this port\n" + " -p [host:]port Start web server on this port\n" " -h Display usage information (this message)\n", PARSER_VERSION, program); @@ -569,7 +570,7 @@ int main(int argc, char *argv[]) { case 'p': if(optind < argc - 1){ optind++; - httpd_port=argv[optind]; + httpd_host_port=argv[optind]; } break; #ifdef WITH_MAILRECEIVE @@ -587,7 +588,7 @@ int main(int argc, char *argv[]) { } if (optind > argc - 1) { - if(!httpd_port) { + if(!httpd_host_port) { fprintf(stderr, "%s: file not specified\n", argv[0]); usage(argv[0]); } @@ -596,7 +597,7 @@ int main(int argc, char *argv[]) { } args_skip=optind; - if (httpd_port && mail_received) { + if (httpd_host_port && mail_received) { fprintf(stderr, "%s: -p and -m options should not be used together\n", argv[0]); usage(argv[0]); }