--- parser3/src/targets/isapi/parser3isapi.C 2001/03/23 10:27:34 1.9 +++ parser3/src/targets/isapi/parser3isapi.C 2001/03/23 14:03:29 1.12 @@ -1,5 +1,5 @@ #ifndef _MSC_VER -# error compile ISAPI module with MSVC +# error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] #endif #include @@ -96,7 +96,7 @@ void SAPI::send_header(Pool& pool) { sapi_func_context& ctx=*static_cast(pool.context()); ctx.header->APPEND_CONST( - "Expires: Fri, 23 Mar 2001 09:32:23 GMT\n" + "expires: Fri, 23 Mar 2001 09:32:23 GMT\n" "\n"); HSE_SEND_HEADER_EX_INFO header_info; @@ -169,11 +169,10 @@ BOOL WINAPI GetExtensionVersion(HSE_VERS ISAPI // main workhorse @todo - think of a better way than @c APPL_PHYSICAL_PATH - of obtaining the @c DOCUMENT_ROOT - because this only gets "the place where last IIS Application was set" - and if someone would redefine Application settings below the / - all ^table:load[/test] would open not /test but /below/test + IIS: remove trailing default-document[index.html] from $request.uri. + to do that we need to consult metabase, + wich is tested&works but seems slow runtime + and not could-be-quickly-implemented if prepared. */ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) { Pool pool; @@ -182,21 +181,29 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI PTRY { // global try sapi_func_context ctx={ lpECB, - new(pool) String(pool), + 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; - if(!(request_info.document_root=SAPI::get_env(pool, "APPL_PHYSICAL_PATH"))) + const char *filespec_to_process=lpECB->lpszPathTranslated; + 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); + strncpy(buf, filespec_to_process, len); + buf[len]=0; + request_info.document_root=buf; + } else PTHROW(0, 0, 0, - "can not get server variable APPL_PHYSICAL_PATH (error #%lu)", - GetLastError()); // never + "ISAPI: no PATH_INFO defined (in reinventing DOCUMENT_ROOT)"); - request_info.path_translated=lpECB->lpszPathTranslated; + request_info.path_translated=filespec_to_process; request_info.method=lpECB->lpszMethod; request_info.query_string=lpECB->lpszQueryString; if(lpECB->lpszQueryString && *lpECB->lpszQueryString) { @@ -234,25 +241,39 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI header_only); // successful finish - } PCATCH(e) { // global problem + } PCATCH(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(); int content_length=strlen(body); - // prepare header - SAPI::add_header_attribute(pool, "content-type", "text/plain"); - char content_length_cstr[MAX_NUMBER]; - snprintf(content_length_cstr, MAX_NUMBER, "%lu", content_length); - SAPI::add_header_attribute(pool, "content-length", content_length_cstr); - + // prepare header // not using SAPI func wich allocates on pool + char header_buf[MAX_STRING]; + int header_len=snprintf(header_buf, MAX_STRING, + "content-type: text/plain\n" + "content-length: %ul\n" + "expires: Fri, 23 Mar 2001 09:32:23 GMT\n" + "\n", + content_length); + + HSE_SEND_HEADER_EX_INFO header_info; + header_info.pszStatus="200 OK"; + header_info.cchStatus=strlen(header_info.pszStatus); + header_info.pszHeader=header_buf; + header_info.cchHeader=header_len; + header_info.fKeepConn=true; + // send header - SAPI::send_header(pool); + lpECB->dwHttpStatusCode=200; + lpECB->ServerSupportFunction(lpECB->ConnID, + HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); // send body if(!header_only) SAPI::send_body(pool, body, content_length); // unsuccessful finish - _endthread(); } PEND_CATCH