--- parser3/src/targets/isapi/parser3isapi.C 2002/08/01 11:41:21 1.78 +++ parser3/src/targets/isapi/parser3isapi.C 2003/02/17 12:13:45 1.82.2.4 @@ -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/08/01 11:41:21 $"; +static const char* IDENT_PARSER3ISAPI_C="$Date: 2003/02/17 12:13:45 $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -30,7 +30,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 +67,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::log(Pool& pool, const 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 +84,21 @@ void SAPI::log(Pool& pool, const char *f } /// @todo event log -void SAPI::die(const char *fmt, ...) { +void SAPI::die(const char* fmt, ...) { if(FILE *log=fopen("c:\\die.log", "at")) { va_list args; va_start(args,fmt); vfprintf(log, fmt, args); fclose(log); } - exit(1); + // exit & try to produce core dump + abort(); } -const char *SAPI::get_env(Pool& pool, const char *name) { +const char* SAPI::get_env(Pool& pool, const char* name) { SAPI_func_context& ctx=*static_cast(pool.get_context()); - char *variable_buf=(char *)pool.malloc(MAX_STRING); + char *variable_buf=new(pool) char[MAX_STRING]; DWORD variable_len = MAX_STRING-1; if(ctx.lpECB->GetServerVariable(ctx.lpECB->ConnID, const_cast(name), @@ -107,7 +108,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(pool) char[variable_len+1]; if(ctx.lpECB->GetServerVariable(ctx.lpECB->ConnID, const_cast(name), variable_buf, &variable_len)) { @@ -121,7 +122,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,24 +132,23 @@ 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_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; } -const char *const *SAPI::environment(Pool& pool) { +const char* const *SAPI::environment(SAPI_Info& info, Pool& pool) { // we know this buf is writable char *all_http_vars=const_cast(SAPI::get_env(pool, "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(pool) const char*[IIS51var_count+http_var_count+1/*0*/]; + const char* *cur=result; // IIS5.1 vars for(int i=0; i(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"); } } @@ -279,7 +281,7 @@ static bool parser_init() { static Pool pool(&pool_storage); // global pool try { // init socks - init_socks(pool); + pa_init_socks(pool); // init global classes init_methoded_array(pool); // init global variables @@ -288,7 +290,7 @@ static bool parser_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; @@ -322,16 +324,15 @@ void real_parser_handler(Pool& pool, LPE 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(pool, "PATH_INFO")) { // IIS size_t len=strlen(filespec_to_process)-strlen(path_info); - char *buf=(char *)pool.malloc(len+1); + char *buf=new(pool) char[len+1]; strncpy(buf, filespec_to_process, len); buf[len]=0; request_info.document_root=buf; } else @@ -343,9 +344,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(pool) 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); @@ -382,10 +383,11 @@ void real_parser_handler(Pool& pool, LPE snprintf(config_filespec, MAX_STRING, "%s/%s", beside_binary_path, AUTO_FILE_NAME); + bool fail_on_config_read_problem=entry_exists(config_filespec); // process the request request.core( - config_filespec, false /*fail_on_read_problem*/, // /path/to/first/auto.p + config_filespec, fail_on_config_read_problem, // /path/to/first/auto.p header_only); } @@ -422,7 +424,7 @@ inline DWORD RealHttpExtensionProc(LPEXT SAPI_func_context ctx={ lpECB, 0, // filling later: so that if there would be error pool would have ctx - 200 // default http_response_code + 200 // default http_response_code [lpECB->dwHttpStatusCode seems to be always 0, even on 404 redirect to /404.html] }; pool.set_context(&ctx);// no allocations before this line! @@ -434,7 +436,7 @@ inline DWORD RealHttpExtensionProc(LPEXT // 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); @@ -469,7 +471,7 @@ inline DWORD RealHttpExtensionProc(LPEXT // unsuccessful finish } /* - const char *body="test"; + const char* body="test"; // int content_length=strlen(body);