--- parser3/src/targets/isapi/parser3isapi.C 2001/04/03 07:20:55 1.22 +++ parser3/src/targets/isapi/parser3isapi.C 2001/10/09 14:25:30 1.48 @@ -1,7 +1,18 @@ +/** @file + Parser: IIS extension. + + Copyright (c) 2000,2001 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexander Petrosyan (http://design.ru/paf) + + $Id: parser3isapi.C,v 1.48 2001/10/09 14:25:30 parser Exp $ +*/ + #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] #endif +#include "pa_config_includes.h" + #include #include @@ -12,21 +23,65 @@ #include "pa_request.h" #include "pa_version.h" #include "pool_storage.h" +#include "pa_socks.h" #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") +// consts + +extern const char *main_RCSIds[]; +#ifdef USE_SMTP +extern const char *smtp_RCSIds[]; +#endif +extern const char *gd_RCSIds[]; +extern const char *classes_RCSIds[]; +extern const char *types_RCSIds[]; +extern const char *parser3isapi_RCSIds[]; +const char **RCSIds[]={ + main_RCSIds, +#ifdef USE_SMTP + smtp_RCSIds, +#endif + gd_RCSIds, + classes_RCSIds, + types_RCSIds, + parser3isapi_RCSIds, +#ifdef XML + xalan_patched_RCSIds, +#endif + 0 +}; + // SAPI -/** +#ifndef DOXYGEN +/* ISAPI SAPI functions receive this context information. - - @see Pool::set_context + see Pool::set_context */ struct SAPI_func_context { LPEXTENSION_CONTROL_BLOCK lpECB; String *header; DWORD http_response_code; }; +#endif + +// goes to 'cs-uri-query' log file field. webmaster: switch it ON[default OFF]. +void SAPI::log(Pool& pool, const char *fmt, ...) { + SAPI_func_context& ctx=*static_cast(pool.context()); + + va_list args; + va_start(args,fmt); + char buf[MAX_STRING]; + const char *prefix="PARSER_ERROR:"; + strcpy(buf, prefix); + char *start=buf+strlen(prefix); + size_t size=vsnprintf(start, MAX_STRING-strlen(prefix), fmt, args); + remove_crlf(start, start+size); + + ctx.lpECB->ServerSupportFunction(ctx.lpECB->ConnID, + HSE_APPEND_LOG_PARAMETER, buf, &size, 0); +} const char *SAPI::get_env(Pool& pool, const char *name) { SAPI_func_context& ctx=*static_cast(pool.context()); @@ -51,7 +106,7 @@ const char *SAPI::get_env(Pool& pool, co return 0; } -uint SAPI::read_post(Pool& pool, char *buf, uint max_bytes) { +size_t SAPI::read_post(Pool& pool, char *buf, size_t max_bytes) { SAPI_func_context& ctx=*static_cast(pool.context()); DWORD read_from_buf=0; @@ -93,17 +148,17 @@ void SAPI::add_header_attribute(Pool& po ctx.header->APPEND_CONST(key); ctx.header->APPEND_CONST(": "); ctx.header->APPEND_CONST(value); - ctx.header->APPEND_CONST("\n"); + ctx.header->APPEND_CONST("\r\n"); } } -/// @todo parser4: intelligent cache-control +/// @todo intelligent cache-control 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" - "\n"); + "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n" + "\r\n"); HSE_SEND_HEADER_EX_INFO header_info; char status_buf[MAX_STATUS_LENGTH]; @@ -134,27 +189,12 @@ void SAPI::send_header(Pool& pool) { HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); } -void SAPI::send_body(Pool& pool, const char *buf, size_t size) { +void SAPI::send_body(Pool& pool, const void *buf, size_t size) { SAPI_func_context& ctx=*static_cast(pool.context()); DWORD num_bytes=size; ctx.lpECB->WriteClient(ctx.lpECB->ConnID, - const_cast(buf), &num_bytes, HSE_IO_SYNC); -} - -// goes to 'cs-uri-query' log file field. webmaster: switch it ON[default OFF]. -void SAPI::log(Pool& pool, const char *fmt, ...) { - SAPI_func_context& ctx=*static_cast(pool.context()); - - va_list args; - va_start(args,fmt); - char buf[MAX_STRING]; - const char *prefix="PARSER_ERROR:"; - strcpy(buf, prefix); - DWORD size=vsnprintf(buf+strlen(prefix), MAX_STRING-strlen(prefix), fmt, args); - - ctx.lpECB->ServerSupportFunction(ctx.lpECB->ConnID, - HSE_APPEND_LOG_PARAMETER, buf, &size, 0); + const_cast(buf), &num_bytes, HSE_IO_SYNC); } // @@ -167,6 +207,11 @@ static bool parser_init() { static Pool pool(0); // global pool PTRY { + // init socks + init_socks(pool); + + // init global classes + init_methoded_array(pool); // init global variables pa_globals_init(pool); @@ -184,18 +229,21 @@ static bool 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); + strncpy(pVer->lpszExtensionDesc, "Parser "PARSER_VERSION, HSE_MAX_EXT_DLL_NAME_LEN-1); + pVer->lpszExtensionDesc[HSE_MAX_EXT_DLL_NAME_LEN-1]=0; return parser_init(); } /** ISAPI // main workhorse - @todo parser4: + @todo 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. + @test + PARSER_VERSION from outside */ DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) { Pool_storage pool_storage; @@ -203,8 +251,9 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI SAPI_func_context ctx={ lpECB, 0, // filling later: so that if there would be error pool would have ctx - 200 + 200 // default http_response_code }; + _asm nop; // int 3; pool.set_context(&ctx);// no allocations before this line! bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0; @@ -225,8 +274,7 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI // 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; + strncpy(buf, filespec_to_process, len); buf[len]=0; request_info.document_root=buf; } else PTHROW(0, 0, @@ -256,26 +304,30 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI // prepare to process request Request request(pool, request_info, - String::UL_HTML_TYPO + String::UL_USER_HTML ); // some root-controlled location // c:\windows + char root_config_path[MAX_STRING]; + GetWindowsDirectory(root_config_path, MAX_STRING); // must be dynamic: rethrowing from request.core // may return 'source' which can be inside of 'root auto.p@exeception' - char *root_auto_path=(char *)pool.malloc(MAX_STRING); - GetWindowsDirectory(root_auto_path, MAX_STRING); + char *root_config_filespec=(char *)pool.malloc(MAX_STRING); + snprintf(root_config_filespec, MAX_STRING, + "%s/%s", + root_config_path, CONFIG_FILE_NAME); // process the request request.core( - root_auto_path, false/*may be abcent*/, // /path/to/admin/auto.p + root_config_filespec, 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: // possible pool' exception not catch-ed now - // and there could be out-of-memory exception + // and there could be out-of-memory exception const char *body=e.comment(); // log it SAPI::log(pool, "exception in request exception handler: %s", body); @@ -286,10 +338,10 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI // 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-type: text/plain\r\n" + "content-length: %lu\r\n" + "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n" + "\r\n", content_length); HSE_SEND_HEADER_EX_INFO header_info;