--- parser3/src/targets/isapi/parser3isapi.C 2001/03/23 14:03:29 1.12 +++ parser3/src/targets/isapi/parser3isapi.C 2001/03/24 11:33:29 1.15 @@ -11,19 +11,20 @@ #include "pa_globals.h" #include "pa_request.h" #include "pa_version.h" +#include "pool_storage.h" #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") //@{ /// SAPI funcs decl -struct sapi_func_context { +struct SAPI_func_context { LPEXTENSION_CONTROL_BLOCK lpECB; String *header; DWORD http_response_code; }; const char *SAPI::get_env(Pool& pool, const char *name) { - sapi_func_context& ctx=*static_cast(pool.context()); + SAPI_func_context& ctx=*static_cast(pool.context()); char *variable_buf=(char *)pool.malloc(MAX_STRING); DWORD variable_len = MAX_STRING-1; @@ -46,7 +47,7 @@ const char *SAPI::get_env(Pool& pool, co } uint SAPI::read_post(Pool& pool, char *buf, uint max_bytes) { - sapi_func_context& ctx=*static_cast(pool.context()); + SAPI_func_context& ctx=*static_cast(pool.context()); DWORD read_from_buf=0; DWORD read_from_input=0; @@ -76,7 +77,7 @@ uint SAPI::read_post(Pool& pool, char *b } void SAPI::add_header_attribute(Pool& pool, const char *key, const char *value) { - sapi_func_context& ctx=*static_cast(pool.context()); + SAPI_func_context& ctx=*static_cast(pool.context()); if(strcasecmp(key, "location")==0) ctx.http_response_code=302; @@ -93,7 +94,7 @@ void SAPI::add_header_attribute(Pool& po /// @todo intelligent cache-control void SAPI::send_header(Pool& pool) { - sapi_func_context& ctx=*static_cast(pool.context()); + SAPI_func_context& ctx=*static_cast(pool.context()); ctx.header->APPEND_CONST( "expires: Fri, 23 Mar 2001 09:32:23 GMT\n" @@ -129,7 +130,7 @@ void SAPI::send_header(Pool& pool) { } void SAPI::send_body(Pool& pool, const char *buf, size_t size) { - sapi_func_context& ctx=*static_cast(pool.context()); + SAPI_func_context& ctx=*static_cast(pool.context()); DWORD num_bytes=size; ctx.lpECB->WriteClient(ctx.lpECB->ConnID, @@ -139,21 +140,24 @@ void SAPI::send_body(Pool& pool, const c // -static void parser_init() { +static bool parser_init() { static bool globals_inited=false; if(globals_inited) - return; + return true; globals_inited=true; - static Pool pool; // global pool + static Pool pool(0); // global pool PTRY { // init global variables pa_globals_init(pool); - //... + // successful finish + return true; } PCATCH(e) { // global problem - const char *body=e.comment(); - // TODO: somehow report that error + //const char *body=e.comment(); + + // unsuccessful finish + return false; } PEND_CATCH } @@ -161,8 +165,8 @@ static void parser_init() { /// ISAPI // BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) { pVer->dwExtensionVersion = HSE_VERSION; - strncpy(pVer->lpszExtensionDesc, "Parser " PARSER_VERSION, HSE_MAX_EXT_DLL_NAME_LEN); - return TRUE; + strncpy(pVer->lpszExtensionDesc, "Parser "PARSER_VERSION, HSE_MAX_EXT_DLL_NAME_LEN); + return parser_init(); } /** @@ -175,22 +179,29 @@ BOOL WINAPI GetExtensionVersion(HSE_VERS and not could-be-quickly-implemented if prepared. */ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) { - Pool pool; + Pool_storage pool_storage; + Pool pool(&pool_storage); // no allocations until assigned context [for reporting] + SAPI_func_context ctx={ + lpECB, + 0, // filling later: so that if there would be error pool would have ctx + 200 + }; + pool.set_context(&ctx);// no allocations before this line! bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0; PTRY { // global try - sapi_func_context ctx={ - lpECB, - 0, // filling later: so that if there would be error pool would have ctx - 200 - }; - pool.set_context(&ctx); ctx.header=new(pool) String(pool); // Request info Request::Info request_info; - - const char *filespec_to_process=lpECB->lpszPathTranslated; + + size_t path_translated_buf_size=strlen(lpECB->lpszPathTranslated)+1; + char *filespec_to_process=(char *)malloc(path_translated_buf_size); + memcpy(filespec_to_process, 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")) { // IIS size_t len=strlen(filespec_to_process)-strlen(path_info); @@ -226,7 +237,7 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI request_info, String::UL_HTML_TYPO ); - + // some root-controlled location // c:\windows // must be dynamic: rethrowing from request.core @@ -239,7 +250,6 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI root_auto_path, false/*may be abcent*/, // /path/to/admin/auto.p 0/*parser_site_auto_path*/, false, // /path/to/site/auto.p header_only); - // successful finish } PCATCH(e) { // global problem // don't allocate anything on pool here: @@ -280,14 +290,13 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI return HSE_STATUS_SUCCESS_AND_KEEP_CONN; } - +/* BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: - parser_init(); break; case DLL_THREAD_ATTACH: break; @@ -298,3 +307,4 @@ BOOL APIENTRY DllMain(HANDLE hModule, } return TRUE; } +*/ \ No newline at end of file