--- parser3/src/targets/isapi/parser3isapi.C 2002/10/29 11:28:19 1.80 +++ parser3/src/targets/isapi/parser3isapi.C 2003/03/20 14:19:10 1.82.2.6.2.3 @@ -1,11 +1,11 @@ /** @file Parser: IIS extension. - Copyright (c) 2000,2001, 2002 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2000,2001-2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_PARSER3ISAPI_C="$Date: 2002/10/29 11:28:19 $"; +static const char* IDENT_PARSER3ISAPI_C="$Date: 2003/03/20 14:19:10 $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -22,7 +22,6 @@ static const char* IDENT_PARSER3ISAPI_C= #include #include -#include #include @@ -30,7 +29,7 @@ static const char* IDENT_PARSER3ISAPI_C= // consts -const char *IIS51vars[]={ +const char* IIS51vars[]={ "APPL_MD_PATH", "APPL_PHYSICAL_PATH", "AUTH_PASSWORD", "AUTH_TYPE", "AUTH_USER", "CERT_COOKIE", "CERT_FLAGS", "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE", @@ -67,13 +66,13 @@ struct SAPI_func_context { #endif // goes to 'cs-uri-query' log file field. webmaster: switch it ON[default OFF]. -void SAPI::log(Pool& pool, const char *fmt, ...) { +void SAPI::logconst char* fmt, ...) { SAPI_func_context& ctx=*static_cast(pool.get_context()); va_list args; va_start(args,fmt); char buf[MAX_STRING]; - const char *prefix="PARSER_ERROR:"; + const char* prefix="PARSER_ERROR:"; strcpy(buf, prefix); char *start=buf+strlen(prefix); DWORD size=vsnprintf(start, MAX_STRING-strlen(prefix), fmt, args); @@ -84,20 +83,32 @@ void SAPI::log(Pool& pool, const char *f } /// @todo event log -void SAPI::die(const char *fmt, ...) { - if(FILE *log=fopen("c:\\die.log", "at")) { - va_list args; - va_start(args,fmt); +static void die_or_abort(const char* fmt, va_list args, bool write_core) { + if(FILE *log=fopen("c:\\parser3die.log", "at")) { vfprintf(log, fmt, args); fclose(log); } - exit(1); + // exit & try to produce core dump + abort(); +} +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) { +const char* SAPI::get_envconst char* name) { SAPI_func_context& ctx=*static_cast(pool.get_context()); - char *variable_buf=(char *)pool.malloc(MAX_STRING); + char *variable_buf=new char[MAX_STRING]; DWORD variable_len = MAX_STRING-1; if(ctx.lpECB->GetServerVariable(ctx.lpECB->ConnID, const_cast(name), @@ -107,7 +118,7 @@ const char *SAPI::get_env(Pool& pool, co return variable_buf; } } else if (GetLastError()==ERROR_INSUFFICIENT_BUFFER) { - variable_buf=(char *)pool.malloc(variable_len+1); + variable_buf=new char[variable_len+1]; if(ctx.lpECB->GetServerVariable(ctx.lpECB->ConnID, const_cast(name), variable_buf, &variable_len)) { @@ -121,7 +132,7 @@ const char *SAPI::get_env(Pool& pool, co return 0; } -static int grep_char(const char *s, char c) { +static int grep_char(const char* s, char c) { int result=0; if(s) { while(s=strchr(s, c)) { @@ -131,32 +142,31 @@ static int grep_char(const char *s, char } return result; } -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_pairconst char* key, const char* value) { + char *result=new char[strlen(key)+1/*=*/+strlen(value)+1/*0*/]; strcpy(result, key); strcat(result, "="); strcat(result, value); return result; } -const char *const *SAPI::environment(Pool& pool) { +const char* const *SAPI::environment(SAPI_Info& info, ) { // we know this buf is writable - char *all_http_vars=const_cast(SAPI::get_env(pool, "ALL_HTTP")); + const char* all_http_vars=SAPI::get_env("ALL_HTTP"); const int http_var_count=grep_char(all_http_vars, '\n')+1/*\n for theoretical(never saw) this \0*/; - const char **result= - (const char **)pool.malloc(sizeof(char *)*(IIS51var_count+http_var_count+1/*0*/)); - const char **cur=result; + const char* *result=new const char*[IIS51var_count+http_var_count+1/*0*/]; + const char* *cur=result; // IIS5.1 vars for(int i=0; i(pool.get_context()); DWORD read_from_buf=0; @@ -195,24 +205,26 @@ size_t SAPI::read_post(Pool& pool, char return total_read; } -void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) { +void SAPI::add_header_attribute + const char* dont_store_key, const char* dont_store_value) { SAPI_func_context& ctx=*static_cast(pool.get_context()); if(strcasecmp(key, "location")==0) ctx.http_response_code=302; if(strcasecmp(key, "status")==0) - ctx.http_response_code=atoi(value); + ctx.http_response_code=atoi(dont_store_value); else { - ctx.header->APPEND_CONST(key); +todo: copy dont_store_ to nonvilotile + ctx.header->APPEND_CONST(dont_store_key); ctx.header->APPEND_CONST(": "); - ctx.header->APPEND_CONST(value); + ctx.header->APPEND_CONST(dont_store_value); ctx.header->APPEND_CONST("\r\n"); } } /// @todo intelligent cache-control -void SAPI::send_header(Pool& pool) { +void SAPI::send_header() { SAPI_func_context& ctx=*static_cast(pool.get_context()); HSE_SEND_HEADER_EX_INFO header_info; @@ -237,7 +249,7 @@ void SAPI::send_header(Pool& pool) { header_info.cchStatus=strlen(header_info.pszStatus); *ctx.header << "\r\n"; // ISAPI v<5 did quite well without it header_info.pszHeader=ctx.header->cstr(); - header_info.cchHeader=ctx.header->size(); + header_info.cchHeader=ctx.header->length(); header_info.fKeepConn=true; ctx.lpECB->dwHttpStatusCode=ctx.http_response_code; @@ -246,7 +258,7 @@ void SAPI::send_header(Pool& pool) { HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); } -void SAPI::send_body(Pool& pool, const void *buf, size_t size) { +void SAPI::send_bodyconst void *buf, size_t size) { SAPI_func_context& ctx=*static_cast(pool.get_context()); DWORD num_bytes=size; @@ -254,41 +266,26 @@ void SAPI::send_body(Pool& pool, const v const_cast(buf), &num_bytes, HSE_IO_SYNC); } -// - -int failed_new(size_t size) { - SAPI::die("out of memory in 'new', failed to allocated %u bytes", size); - return 0; // not reached -} -#ifdef _DEBUG -static Pool_storage *global_pool_storagep; -#endif static bool parser_init() { static bool globals_inited=false; if(globals_inited) return true; globals_inited=true; - _set_new_handler(failed_new); - - static Pool_storage pool_storage; -#ifdef _DEBUG - global_pool_storagep=&pool_storage; -#endif static Pool pool(&pool_storage); // global pool try { // init socks - init_socks(pool); + pa_init_socks(); // init global classes - init_methoded_array(pool); + init_methoded_array(); // init global variables - pa_globals_init(pool); + pa_globals_init(); // successful finish return true; } catch(const Exception& e) { // global problem - const char *body=e.comment(); + const char* body=e.comment(); // unsuccessful finish return false; @@ -315,23 +312,22 @@ BOOL WINAPI GetExtensionVersion(HSE_VERS PARSER_VERSION from outside */ -void real_parser_handler(Pool& pool, LPEXTENSION_CONTROL_BLOCK lpECB, bool header_only) { - static_cast(pool.get_context())->header=new(pool) String(pool); +void real_parser_handlerLPEXTENSION_CONTROL_BLOCK lpECB, bool header_only) { + static_cast(pool.get_context())->header=new String(); // Request info Request::Info request_info; size_t path_translated_buf_size=strlen(lpECB->lpszPathTranslated)+1; - char *filespec_to_process=(char *)pool.malloc(path_translated_buf_size); - memcpy(filespec_to_process, lpECB->lpszPathTranslated, path_translated_buf_size); + char *filespec_to_process=pool.copy(lpECB->lpszPathTranslated, path_translated_buf_size); #ifdef WIN32 back_slashes_to_slashes(filespec_to_process); #endif - if(const char *path_info=SAPI::get_env(pool, "PATH_INFO")) { + if(const char* path_info=SAPI::get_env("PATH_INFO")) { // IIS size_t len=strlen(filespec_to_process)-strlen(path_info); - char *buf=(char *)pool.malloc(len+1); + char *buf=new char[len+1]; strncpy(buf, filespec_to_process, len); buf[len]=0; request_info.document_root=buf; } else @@ -343,9 +339,9 @@ void real_parser_handler(Pool& pool, LPE request_info.method=lpECB->lpszMethod; request_info.query_string=lpECB->lpszQueryString; if(lpECB->lpszQueryString && *lpECB->lpszQueryString) { - char *reconstructed_uri=(char *)pool.malloc( + char *reconstructed_uri=new char[ strlen(lpECB->lpszPathInfo)+1/*'?'*/+ - strlen(lpECB->lpszQueryString)+1/*0*/); + strlen(lpECB->lpszQueryString)+1/*0*/]; strcpy(reconstructed_uri, lpECB->lpszPathInfo); strcat(reconstructed_uri, "?"); strcat(reconstructed_uri, lpECB->lpszQueryString); @@ -355,7 +351,7 @@ void real_parser_handler(Pool& pool, LPE request_info.content_type=lpECB->lpszContentType; request_info.content_length=lpECB->cbTotalBytes; - request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); + request_info.cookie=SAPI::get_env("HTTP_COOKIE"); request_info.mail_received=false; // prepare to process request @@ -390,14 +386,14 @@ void real_parser_handler(Pool& pool, LPE header_only); } -void call_real_parser_handler__do_SEH(Pool& pool, +void call_real_parser_handler__do_SEH LPEXTENSION_CONTROL_BLOCK lpECB, bool header_only) { #if _MSC_VER & !defined(_DEBUG) LPEXCEPTION_POINTERS system_exception=0; __try { #endif - real_parser_handler(pool, lpECB, header_only); + real_parser_handler(lpECB, header_only); #if _MSC_VER & !defined(_DEBUG) } __except ( @@ -429,15 +425,15 @@ inline DWORD RealHttpExtensionProc(LPEXT bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0; try { // global try - call_real_parser_handler__do_SEH(pool, lpECB, header_only); + call_real_parser_handler__do_SEH(lpECB, header_only); // successful finish } catch(const Exception& e) { // global problem // 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); + SAPI::log("exception in request exception handler: %s", body); // int content_length=strlen(body); @@ -465,12 +461,12 @@ inline DWORD RealHttpExtensionProc(LPEXT // send body if(!header_only) - SAPI::send_body(pool, body, content_length); + SAPI::send_body(body, content_length); // unsuccessful finish } /* - const char *body="test"; + const char* body="test"; // int content_length=strlen(body);