--- parser3/src/targets/apache13/Attic/mod_parser3.C 2002/08/01 11:41:20 1.26 +++ parser3/src/targets/apache13/Attic/mod_parser3.C 2003/02/26 11:51:15 1.28.2.6 @@ -1,18 +1,14 @@ /** @file Parser: apache 1.3 module. - Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_MOD_PARSER3_C="$Date: 2002/08/01 11:41:20 $"; +static const char* IDENT_MOD_PARSER3_C="$Date: 2003/02/26 11:51:15 $"; #include "pa_config_includes.h" -#if _MSC_VER -# include -#endif - #include "pa_globals.h" #include "httpd.h" @@ -50,7 +46,7 @@ static Parser_module_config *our_dconfig ap_get_module_config(r->per_dir_config, &parser3_module); } -static const char *cmd_parser_config(cmd_parms *cmd, void *mconfig, char *file_spec) { +static const char* cmd_parser_config(cmd_parms *cmd, void *mconfig, char *file_spec) { Parser_module_config *cfg = (Parser_module_config *) mconfig; // remember assigned filespec into cfg @@ -58,7 +54,7 @@ static const char *cmd_parser_config(cmd return NULL; } -static const char *cmd_parser_status_allowed(cmd_parms *cmd, void *mconfig, char *file_spec) { +static const char* cmd_parser_status_allowed(cmd_parms *cmd, void *mconfig, char *file_spec) { //_asm int 3; Parser_module_config *cfg = (Parser_module_config *) mconfig; @@ -96,7 +92,7 @@ static const char *cmd_parser_status_all //@{ /// SAPI func decl -void SAPI::log(Pool& pool, const char *fmt, ...) { +void SAPI::log(Pool& pool, const char* fmt, ...) { request_rec *r=static_cast(pool.get_context()); va_list args; @@ -108,35 +104,50 @@ void SAPI::log(Pool& pool, const char *f va_end(args); } -void SAPI::die(const char *fmt, ...) { - va_list args; - va_start(args,fmt); +static void die_or_abort(const char* fmt, va_list args, bool write_core) { char buf[MAX_STRING]; size_t size=vsnprintf(buf, MAX_STRING, fmt, args); remove_crlf(buf, buf+size); ap_log_error(APLOG_MARK, APLOG_EMERG, 0, "%s", buf); - va_end(args); - exit(1); + // exit & try to produce core dump + if(write_core) + abort(); + else + exit(1); +} + +void SAPI::die(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + die_or_abort(fmt, args, false/*write core?*/); + va_end(args); +} + +void SAPI::abort(const char* fmt, ...) { + va_list args; + va_start(args, fmt); + die_or_abort(fmt, args, true/*write core?*/); + va_end(args); } -const char *SAPI::get_env(Pool& pool, const char *name) { +char* SAPI::get_env(SAPI_Info& info, const char* name) { request_rec *r=static_cast(pool.get_context()); - return (const char *)ap_table_get(r->subprocess_env, name); + return (const char* )ap_table_get(r->subprocess_env, name); } #ifndef DOXYGEN struct SAPI_environment_append_info { Pool *pool; - const char **cur; + const char* *cur; }; #endif -static const char *mk_env_pair(Pool& pool, const char *key, const char *value) { - char *result=(char *)pool.malloc(strlen(key)+1/*=*/+strlen(value)+1/*0*/); +static const char* mk_env_pair(Pool& pool, const char* key, const char* value) { + char *result=new(pool) char[strlen(key)+1/*=*/+strlen(value)+1/*0*/]; strcpy(result, key); strcat(result, "="); strcat(result, value); return result; } -static int SAPI_environment_append(void *d, const char *k, const char *val) { +static int SAPI_environment_append(void *d, const char* k, const char* val) { if( k && val ) { SAPI_environment_append_info& info= *static_cast(d); @@ -144,11 +155,10 @@ static int SAPI_environment_append(void } return 1/*true*/; } -const char *const *SAPI::environment(Pool& pool) { +const char* const *SAPI::environment(SAPI_Info& info, Pool& pool) { request_rec *r=static_cast(pool.get_context()); const table *t=r->subprocess_env; - const char **result= - (const char **)pool.malloc(sizeof(char *)*(ap_table_elts(t)->nelts+1/*0*/)); + const char* *result=new(pool) const char*[ap_table_elts(t)->nelts+1/*0*/]; SAPI_environment_append_info info={&pool, result}; ap_table_do(SAPI_environment_append, &info, t, 0); *info.cur=0; // mark EOE return result; @@ -182,7 +192,8 @@ size_t SAPI::read_post(Pool& pool, char } /// @test location provide with protocol. think about internal redirects -void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) { +void SAPI::add_header_attribute(Pool& pool, + const char* dont_store_key, const char* dont_store_value) { request_rec *r=static_cast(pool.get_context()); if(strcasecmp(key, "location")==0) @@ -198,6 +209,7 @@ void SAPI::add_header_attribute(Pool& po } else if(strcasecmp(key, "status")==0) r->status=atoi(value); else +todo: copy dont_store_ to nonvilotile ap_table_addn(r->headers_out, key, value); } @@ -236,7 +248,7 @@ static void real_parser_handler(Pool& po request_info.query_string=r->args; request_info.uri=SAPI::get_env(pool, "REQUEST_URI"); request_info.content_type=SAPI::get_env(pool, "CONTENT_TYPE"); - const char *content_length=SAPI::get_env(pool, "CONTENT_LENGTH"); + CharPtr content_length=SAPI::get_env(pool, "CONTENT_LENGTH"); request_info.content_length=content_length?atoi(content_length):0; request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); request_info.mail_received=false; @@ -304,7 +316,7 @@ static int parser_handler(request_rec *r // don't allocate anything on pool here: // possible pool' exception not catch-ed now // and there could be out-of-memory exception - const char *body=e.comment(); + const char* body=e.comment(); // log it SAPI::log(pool, "exception in request exception handler: %s", body); @@ -334,19 +346,6 @@ static int parser_handler(request_rec *r return OK; } -#if _MSC_VER -int failed_new(size_t size) { - SAPI::die("out of memory in 'new', failed to allocated %u bytes", size); - return 0; // not reached -} -#endif - -#ifdef HAVE_SET_NEW_HANDLER -void failed_new() { - SAPI::die("out of memory in 'new'"); -} -#endif - /*--------------------------------------------------------------------------*/ /* */ /* Now let's declare routines for each of the callback phase in order. */ @@ -390,14 +389,6 @@ static void setup_module_cells() { return; globals_inited=true; -#ifdef WIN32 - _set_new_handler(failed_new); -#endif - -#ifdef HAVE_SET_NEW_HANDLER - std::set_new_handler(failed_new); -#endif - /* * allocate our module-private pool. */ @@ -405,14 +396,14 @@ static void setup_module_cells() { /// no trying to __try here [yet] try { // init socks - init_socks(pool); + pa_init_socks(pool); // init global classes init_methoded_array(pool); // init global variables pa_globals_init(pool); } catch(const Exception& e) { // global problem - SAPI::die("setup_module_cells failed: %s", e.comment()); + SAPI::abort("setup_module_cells failed: %s", e.comment()); } } @@ -623,7 +614,7 @@ static const command_rec parser_cmds[] = { { "ParserConfig", /* directive name */ - (const char *(*)(void))((void *)cmd_parser_config), // config action routine + (const char* (*)(void))((void *)cmd_parser_config), // config action routine (void*)0, /* argument to include in call */ (int)(OR_OPTIONS), /* where available */ TAKE1, /* arguments */ @@ -631,7 +622,7 @@ static const command_rec parser_cmds[] = }, { "ParserStatusAllowed", /* directive name */ - (const char *(*)(void))((void *)cmd_parser_status_allowed), // config action routine + (const char* (*)(void))((void *)cmd_parser_status_allowed), // config action routine (void*)0, /* argument to include in call */ (int)(ACCESS_CONF), /* where available */ NO_ARGS, /* arguments */