--- parser3/src/targets/isapi/parser3isapi.C 2001/03/24 14:31:02 1.16 +++ parser3/src/targets/isapi/parser3isapi.C 2001/06/28 07:44:17 1.35 @@ -1,3 +1,12 @@ +/** @file + Parser: IIS extension. + + Copyright (c) 2000,2001 ArtLebedev Group (http://www.artlebedev.com) + + Author: Alexander Petrosyan (http://design.ru/paf) +*/ +static const char *RCSId="$Id: parser3isapi.C,v 1.35 2001/06/28 07:44:17 parser Exp $"; + #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] #endif @@ -12,19 +21,38 @@ #include "pa_request.h" #include "pa_version.h" #include "pool_storage.h" - -#include "nt_log_events.h" +#include "pa_socks.h" #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") -//@{ -/// SAPI funcs decl +// SAPI + +/** + ISAPI SAPI functions receive this context information. + + @see Pool::set_context +*/ struct SAPI_func_context { LPEXTENSION_CONTROL_BLOCK lpECB; String *header; DWORD http_response_code; }; +// 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 char *SAPI::get_env(Pool& pool, const char *name) { SAPI_func_context& ctx=*static_cast(pool.context()); @@ -48,7 +76,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; @@ -90,7 +118,7 @@ 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"); } } @@ -99,8 +127,8 @@ 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]; @@ -131,30 +159,14 @@ 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); + 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); -} -//@} - // static bool parser_init() { @@ -165,6 +177,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); @@ -200,8 +217,8 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI 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 + 0, // filling later: so that if there would be error pool would have ctx + 200 }; pool.set_context(&ctx);// no allocations before this line! @@ -248,11 +265,13 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI request_info.content_type=lpECB->lpszContentType; request_info.content_length=lpECB->cbTotalBytes; request_info.cookie=SAPI::get_env(pool, "HTTP_COOKIE"); + request_info.user_agent=SAPI::get_env(pool, "HTTP_USER_AGENT"); + // prepare to process request Request request(pool, request_info, - String::UL_HTML_TYPO + String::UL_USER_HTML ); // some root-controlled location @@ -271,7 +290,7 @@ DWORD WINAPI HttpExtensionProc(LPEXTENSI } 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); @@ -282,10 +301,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;