--- parser3/src/main/pa_request.C 2026/10/16 13:55:16 1.464 +++ parser3/src/main/pa_request.C 2026/10/22 23:20:42 1.467 @@ -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.464 2026/10/16 13:55:16 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.467 2026/10/22 23:20:42 moko Exp $" IDENT_PA_REQUEST_H IDENT_PA_REQUEST_CHARSETS_H IDENT_PA_REQUEST_INFO_H IDENT_PA_VCONSOLE_H; // consts @@ -59,7 +59,8 @@ const int EXECUTE_RECURSION_RESERVE=100; const int LOOP_LIMIT=100000; const int ARRAY_LIMIT=1000000; const int HTTPD_TIMEOUT=4; -const size_t FILE_SIZE_LIMIT=512*1024*1024; +const size_t FILE_SIZE_LIMIT=512*0x400*0x400; // 512MB +const size_t POST_MAX_SIZE=10*0x400*0x400; // 10MB // defines for globals @@ -84,6 +85,7 @@ 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; // defines for statics @@ -109,6 +111,7 @@ static const String loop_limit_name("max static const String array_limit_name("max_array_size"); static const String recursion_limit_name("max_recursion"); static const String file_size_limit_name("max_file_size"); +static const String post_max_size_name("post_max_size"); static const String lock_wait_timeout_name("lock_wait_timeout"); static const String httpd_name("HTTPD"); static const String httpd_timeout_name("timeout"); @@ -118,6 +121,7 @@ static const String httpd_code_cache_nam #endif static const String conf_method_name("conf"); +static const String mime_types_method_name("mime-types"); static const String post_process_method_name("postprocess"); static const String response_body_file_name("file"); @@ -381,6 +385,15 @@ void Request::configure_admin(VStateless pa_file_size_limit=SSIZE_MAX; }, "LIMITS.%s must be number"); + pa_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; + }, "LIMITS.%s must be number"); + pa_lock_attempts=PA_LOCK_ATTEMPTS; CONF_OPTION(limits, lock_wait_timeout_name, { double limit=option->as_double(); @@ -427,7 +440,7 @@ const char* Request::get_exception_cstr( #define PA_SOURCE_VALUE details.problem_source->cstr(), #define EXCEPTION_CSTR(f1,v1,f2,v2) \ - snprintf(result, MAX_STRING, \ + pa_snprintf(result, MAX_STRING, \ PA_URI_FORMAT \ f1 f2 \ PA_COMMENT_TYPE_FORMAT, \ @@ -484,11 +497,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 @@ -978,7 +986,7 @@ static void output_pieces(Request& r, bo part_length = rg.end-rg.start+1; char buf[MAX_STRING]; - snprintf(buf, MAX_STRING, "bytes %s-%s/%s", pa_uitoa(rg.start), pa_uitoa(rg.end), pa_uitoa(content_length)); + pa_snprintf(buf, MAX_STRING, "bytes %s-%s/%s", pa_uitoa(rg.start), pa_uitoa(rg.end), pa_uitoa(content_length)); SAPI::add_header_attribute(r.sapi_info, HTTP_STATUS, "206"); SAPI::add_header_attribute(r.sapi_info, "content-range", buf); } else { @@ -1109,17 +1117,31 @@ 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: @mime-types[] result or $MAIN:MIME-TYPES + if(!mime_types) { + Value* element=0; + if(const Method *method=main_class.get_method(mime_types_method_name)) { + METHOD_FRAME_ACTION(*method, method_frame/*caller*/, main_class, { + call(frame); + element=&frame.result(); + }); + } else + element=main_class.get_element(mime_types_name); + + Table *table=element ? 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"); }