--- parser3/src/main/pa_request.C 2026/10/18 21:05:35 1.466 +++ parser3/src/main/pa_request.C 2026/11/21 23:38:25 1.475 @@ -37,7 +37,7 @@ #include "pa_varray.h" #include "pa_code_cache.h" -volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.466 2026/10/18 21:05:35 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; +volatile const char * IDENT_PA_REQUEST_C="$Id: pa_request.C,v 1.475 2026/11/21 23:38:25 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts @@ -84,8 +84,8 @@ int pa_loop_limit=LOOP_LIMIT; int pa_array_limit=ARRAY_LIMIT; int pa_execute_recursion_limit=EXECUTE_RECURSION_LIMIT; int pa_httpd_timeout=HTTPD_TIMEOUT; -size_t pa_file_size_limit=FILE_SIZE_LIMIT; -size_t pa_post_max_size=POST_MAX_SIZE; +THREAD_LOCAL size_t pa_file_size_limit=FILE_SIZE_LIMIT; +THREAD_LOCAL size_t pa_post_max_size=POST_MAX_SIZE; // defines for statics @@ -116,6 +116,7 @@ static const String lock_wait_timeout_na static const String httpd_name("HTTPD"); static const String httpd_timeout_name("timeout"); static const String httpd_mode_name("mode"); +static const String httpd_max_connections_name("max-connections"); #ifdef CODE_CACHE static const String httpd_code_cache_name("code-cache"); #endif @@ -154,6 +155,12 @@ void Request::recursion_limit_reached() throw Exception(PARSER_RUNTIME, 0, "call canceled - endless recursion detected"); } +void Request::throw_interrupted() { + finterrupted=0; + set_skip(SKIP_NOTHING); + throw Interrupted_exception(response.timeout); +} + Request::Request(SAPI_Info& asapi_info, Request_info& arequest_info, String::Language adefault_lang): // private anti_endless_execute_recursion(0), @@ -167,6 +174,7 @@ Request::Request(SAPI_Info& asapi_info, fconnection(0), fin_cycle(0), fskip(SKIP_NOTHING), + finterrupted(0), // public request_info(arequest_info), @@ -187,8 +195,6 @@ Request::Request(SAPI_Info& asapi_info, // private mime types mime_types(0) { - pa_register_thread_request(*this); - // file_no=0 => unknown file_list+=String::Body("UNKNOWN"); file_list+=String::Body("-body of process-"); // pseudo_file_no__process @@ -231,9 +237,14 @@ Request::Request(SAPI_Info& asapi_info, put_class(new VMath); // memory class put_class(new VMemory); + + // the last: the destructor is not called if the constructor throws + thread_request=this; } Request::~Request() { + thread_request=0; + #ifdef XML // if for some strange reason xml generic errors failed to be reported, free them up if(const char* xml_generic_errors=xmlGenericErrors()) { @@ -313,115 +324,123 @@ void Request::configure_admin(VStateless } } + Value* conf=&conf_class; + #ifdef STRICT_VARS - VVoid::strict_vars=false; - if(Value* strict_vars=conf_class.get_element(strict_vars_name)) { - if(strict_vars->is_bool()) - VVoid::strict_vars=strict_vars->as_bool(); - else - throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", strict_vars_name.cstr()); - } + bool strict_vars=false; + CONF_OPTION(conf, strict_vars_name, { + strict_vars=option->as_bool(); + }, "%s must be bool"); + VVoid::strict_vars=strict_vars; #endif #ifdef OBJECT_PROTOTYPE - VClass::prototype=true; - if(Value* prototype=conf_class.get_element(prototype_name)) { - if(prototype->is_bool()) - VClass::prototype=prototype->as_bool(); - else - throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", prototype_name.cstr()); - } + bool prototype=true; + CONF_OPTION(conf, prototype_name, { + prototype=option->as_bool(); + }, "%s must be bool"); + VClass::prototype=prototype; #endif #ifdef CLASS_GETTER_UNPROTECTED - VClass::getter_protected=true; - if(Value* getter_protected=conf_class.get_element(getter_protected_name)) { - if(getter_protected->is_bool()) - VClass::getter_protected=getter_protected->as_bool(); - else - throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", getter_protected_name.cstr()); - } + bool getter_protected=true; + CONF_OPTION(conf, getter_protected_name, { + getter_protected=option->as_bool(); + }, "%s must be bool"); + VClass::getter_protected=getter_protected; // thread local: changes in Temp_getter_protected #endif - VStateless_class::gall_vars_local=false; - if(Value* locals=conf_class.get_element(locals_name)) { - if(locals->is_bool()){ - VStateless_class::gall_vars_local=locals->as_bool(); + bool all_vars_local=false; + CONF_OPTION(conf, locals_name, { + all_vars_local=option->as_bool(); + if(all_vars_local) main_class.set_all_vars_local(); - } else - throw Exception(PARSER_RUNTIME, 0, "$MAIN:%s must be bool", locals_name.cstr()); - } + }, "%s must be bool"); + VStateless_class::gall_vars_local=all_vars_local; Value* limits=conf_class.get_element(limits_name); - pa_loop_limit=LOOP_LIMIT; + int loop_limit=LOOP_LIMIT; CONF_OPTION(limits, loop_limit_name, { - pa_loop_limit=option->as_int(); - if(pa_loop_limit==0) pa_loop_limit=INT_MAX; + loop_limit=option->as_int(); + if(loop_limit==0) loop_limit=INT_MAX; }, "LIMITS.%s must be int"); + pa_loop_limit=loop_limit; - pa_array_limit=ARRAY_LIMIT; + int array_limit=ARRAY_LIMIT; CONF_OPTION(limits, array_limit_name, { - pa_array_limit=option->as_int(); - if(pa_array_limit==0) pa_array_limit=INT_MAX; + array_limit=option->as_int(); + if(array_limit==0) array_limit=INT_MAX; }, "LIMITS.%s must be int"); + pa_array_limit=array_limit; - pa_execute_recursion_limit=EXECUTE_RECURSION_LIMIT; + execute_recursion_limit=EXECUTE_RECURSION_LIMIT; CONF_OPTION(limits, recursion_limit_name, { - pa_execute_recursion_limit=option->as_int(); - if(pa_execute_recursion_limit<=0) pa_execute_recursion_limit=INT_MAX; - pa_execute_recursion_limit=min(pa_execute_recursion_limit, INT_MAX-EXECUTE_RECURSION_RESERVE); + execute_recursion_limit=option->as_int(); + if(execute_recursion_limit<=0) execute_recursion_limit=INT_MAX; + execute_recursion_limit=min(execute_recursion_limit, INT_MAX-EXECUTE_RECURSION_RESERVE); }, "LIMITS.%s must be int"); - execute_recursion_limit=pa_execute_recursion_limit; + pa_execute_recursion_limit=execute_recursion_limit; - pa_file_size_limit=FILE_SIZE_LIMIT; + size_t file_size_limit=FILE_SIZE_LIMIT; CONF_OPTION(limits, file_size_limit_name, { double limit=option->as_double(); if(limit >= (double)SSIZE_MAX) throw Exception(PARSER_RUNTIME, 0, "$MAIN:LIMITS.%s must be less than %s", file_size_limit_name.cstr(), pa_itoa(SSIZE_MAX)); - pa_file_size_limit=(size_t)limit; - if(pa_file_size_limit==0) - pa_file_size_limit=SSIZE_MAX; + file_size_limit=(size_t)limit; + if(file_size_limit==0) + file_size_limit=SSIZE_MAX; }, "LIMITS.%s must be number"); + pa_file_size_limit=file_size_limit; // thread local: url-dependent - pa_post_max_size=POST_MAX_SIZE; + size_t post_max_size=POST_MAX_SIZE; CONF_OPTION(limits, post_max_size_name, { double limit=option->as_double(); if(limit >= (double)SSIZE_MAX) throw Exception(PARSER_RUNTIME, 0, "$MAIN:LIMITS.%s must be less than %s", post_max_size_name.cstr(), pa_itoa(SSIZE_MAX)); if(limit > 0) - pa_post_max_size=(size_t)limit; + post_max_size=(size_t)limit; }, "LIMITS.%s must be number"); + pa_post_max_size=post_max_size; // thread local: url-dependent - pa_lock_attempts=PA_LOCK_ATTEMPTS; + unsigned int lock_attempts=PA_LOCK_ATTEMPTS; CONF_OPTION(limits, lock_wait_timeout_name, { double limit=option->as_double(); if(limit >= 3600*24) throw Exception(PARSER_RUNTIME, 0, "$MAIN:LIMITS.%s must be less than %d", lock_wait_timeout_name.cstr(), 3600*24); - pa_lock_attempts=(unsigned int)(limit*2)+1; + lock_attempts=PA_LOCK_TIME_TO_ATTEMPTS(limit); }, "LIMITS.%s must be number"); + pa_lock_attempts=lock_attempts; Value* httpd=conf_class.get_element(httpd_name); - pa_httpd_timeout=HTTPD_TIMEOUT; +#ifdef CODE_CACHE + CONF_OPTION(httpd, httpd_code_cache_name, { + Code_cache_manager::set_enabled(option->as_bool()); + }, "HTTPD.%s must be bool"); +#endif + + int httpd_timeout=HTTPD_TIMEOUT; CONF_OPTION(httpd, httpd_timeout_name, { - pa_httpd_timeout=option->as_int(); - if(pa_httpd_timeout==0) pa_httpd_timeout=INT_MAX; + httpd_timeout=option->as_int(); + if(httpd_timeout==0) httpd_timeout=INT_MAX; + }, "HTTPD.%s must be int"); + pa_httpd_timeout=httpd_timeout; + + int httpd_max_connections=INT_MAX; + CONF_OPTION(httpd, httpd_max_connections_name, { + httpd_max_connections=option->as_int(); + if(httpd_max_connections<=0) httpd_max_connections=INT_MAX; }, "HTTPD.%s must be int"); + HTTPD_Server::max_connections=httpd_max_connections; if(httpd) - if(Value* option=httpd->get_element( httpd_mode_name)) { + if(Value* option=httpd->get_element(httpd_mode_name)) { if(option->get_junction()) throw Exception(PARSER_RUNTIME, 0, "$MAIN:HTTPD:mode must be string"); HTTPD_Server::set_mode(option->as_string()); } -#ifdef CODE_CACHE - CONF_OPTION(httpd, httpd_code_cache_name, { - Code_cache_manager::set_enabled(option->as_bool()); - }, "HTTPD.%s must be bool"); -#endif - // configure method_frame options // until someone with less privileges have overriden them methoded_array().configure_admin(*this); @@ -496,11 +515,6 @@ void Request::configure() { // configure admin options if not configured yet if(!configure_admin_done) configure_admin(main_class); - - // $MAIN:MIME-TYPES - if(Value* element=main_class.get_element(mime_types_name)) - if(Table *table=element->get_table()) - mime_types=table; } /// HEAD request: only the headers are sent @@ -1121,17 +1135,24 @@ const String& Request::mime_type_of(cons } const String& Request::mime_type_of(const char* user_file_name_cstr) { - if(mime_types) - if(const char* cext=strrchr(user_file_name_cstr, '.')) { - String sext(++cext); - Table::Action_options options; - if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER), options)) { - if(const String* result=mime_types->item(1)) - return *result; - else - throw Exception(PARSER_RUNTIME, 0, MIME_TYPES_NAME " table column elements must not be empty"); - } + // built at the first use: $MAIN:MIME-TYPES (table or @GET_MIME-TYPES[] property) + if(!mime_types) { + Value* element=main_class.get_element(mime_types_name); + TEMP_GETTER_PROTECTED(false); // @GET_MIME-TYPES[] assigns $MIME-TYPES, which replaces the getter with the table + Table *table=element ? process(*element).get_table() : 0; + mime_types=table ? table : new Table(0); // empty if nothing is defined + } + + if(const char* cext=strrchr(user_file_name_cstr, '.')) { + String sext(++cext); + Table::Action_options options; + if(mime_types->locate(0, sext.change_case(charsets.source(), String::CC_LOWER), options)) { + if(const String* result=mime_types->item(1)) + return *result; + else + throw Exception(PARSER_RUNTIME, 0, MIME_TYPES_NAME " table column elements must not be empty"); } + } return *new String("application/octet-stream"); }