|
|
| version 1.59, 2001/11/19 08:00:34 | version 1.65, 2002/03/05 07:48:07 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: IIS extension. | Parser: IIS extension. |
| Copyright (c) 2000,2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2000,2001, 2002 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| $Id$ | $Id$ |
| */ | */ |
| Line 13 | Line 13 |
| #include "pa_config_includes.h" | #include "pa_config_includes.h" |
| #include <windows.h> | |
| #include <process.h> | |
| #include <new.h> | |
| #include <httpext.h> | |
| #include "pa_sapi.h" | #include "pa_sapi.h" |
| #include "pa_globals.h" | #include "pa_globals.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| Line 26 | Line 20 |
| #include "pool_storage.h" | #include "pool_storage.h" |
| #include "pa_socks.h" | #include "pa_socks.h" |
| #ifdef XML | #include <windows.h> |
| #include <XalanTransformer/XalanCAPI.h> | #include <process.h> |
| #endif | #include <new.h> |
| #include <httpext.h> | |
| #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") | #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION") |
| Line 42 extern const char *gd_RCSIds[]; | Line 38 extern const char *gd_RCSIds[]; |
| extern const char *classes_RCSIds[]; | extern const char *classes_RCSIds[]; |
| extern const char *types_RCSIds[]; | extern const char *types_RCSIds[]; |
| extern const char *parser3isapi_RCSIds[]; | extern const char *parser3isapi_RCSIds[]; |
| #ifdef XML | |
| extern const char *xalan_patched_RCSIds[]; | |
| #endif | |
| const char **RCSIds[]={ | const char **RCSIds[]={ |
| main_RCSIds, | main_RCSIds, |
| #ifdef USE_SMTP | #ifdef USE_SMTP |
| Line 54 const char **RCSIds[]={ | Line 47 const char **RCSIds[]={ |
| classes_RCSIds, | classes_RCSIds, |
| types_RCSIds, | types_RCSIds, |
| parser3isapi_RCSIds, | parser3isapi_RCSIds, |
| #ifdef XML | |
| xalan_patched_RCSIds, | |
| #endif | |
| 0 | 0 |
| }; | }; |
| // globals | |
| char argv0[MAX_STRING]=""; | |
| // SAPI | // SAPI |
| #ifndef DOXYGEN | #ifndef DOXYGEN |
| Line 74 struct SAPI_func_context { | Line 68 struct SAPI_func_context { |
| }; | }; |
| #endif | #endif |
| #ifdef XML | |
| /** | |
| * Terminate Xalan and Xerces. | |
| * | |
| * Should be called only once per process after deleting all | |
| * instances of XalanTransformer. Once a process has called | |
| * this function, it cannot use the API for the remaining | |
| * lifetime of the process. | |
| this requirement is fullfilled by using Pool::register_cleanup | |
| */ | |
| void callXalanTerminate(void *) { | |
| //_asm int 3; | |
| XalanTerminate(); | |
| } | |
| #endif | |
| // goes to 'cs-uri-query' log file field. webmaster: switch it ON[default OFF]. | // 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<SAPI_func_context *>(pool.get_context()); | SAPI_func_context& ctx=*static_cast<SAPI_func_context *>(pool.get_context()); |
| Line 111 void SAPI::log(Pool& pool, const char *f | Line 87 void SAPI::log(Pool& pool, const char *f |
| /// @todo event log | /// @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(1); |
| } | } |
| Line 187 void SAPI::add_header_attribute(Pool& po | Line 169 void SAPI::add_header_attribute(Pool& po |
| void SAPI::send_header(Pool& pool) { | void SAPI::send_header(Pool& pool) { |
| SAPI_func_context& ctx=*static_cast<SAPI_func_context *>(pool.get_context()); | SAPI_func_context& ctx=*static_cast<SAPI_func_context *>(pool.get_context()); |
| ctx.header->APPEND_CONST( | |
| "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n" | |
| "\r\n"); | |
| HSE_SEND_HEADER_EX_INFO header_info; | HSE_SEND_HEADER_EX_INFO header_info; |
| char status_buf[MAX_STATUS_LENGTH]; | char status_buf[MAX_STATUS_LENGTH]; |
| Line 243 static bool parser_init() { | Line 222 static bool parser_init() { |
| _set_new_handler(failed_new); | _set_new_handler(failed_new); |
| static Pool pool(0); // global pool | static Pool_storage pool_storage; |
| static Pool pool(&pool_storage); // global pool | |
| try { | try { |
| // init socks | // init socks |
| init_socks(pool); | init_socks(pool); |
| #ifdef XML | |
| /** | |
| * Initialize Xerces and Xalan. | |
| * | |
| * Should be called only once per process before making | |
| * any other API calls. | |
| */ | |
| //_asm int 3; | |
| XalanInitialize(); | |
| pool.register_cleanup(callXalanTerminate, 0); | |
| #endif | |
| // init global classes | // init global classes |
| init_methoded_array(pool); | init_methoded_array(pool); |
| // init global variables | // init global variables |
| pa_globals_init(pool); | pa_globals_init(pool); |
| // successful finish | // successful finish |
| return true; | return true; |
| } catch(const Exception& e) { // global problem | } catch(const Exception& e) { // global problem |
| Line 342 void real_parser_handler(Pool& pool, LPE | Line 309 void real_parser_handler(Pool& pool, LPE |
| // prepare to process request | // prepare to process request |
| Request request(pool, | Request request(pool, |
| request_info, | request_info, |
| String::UL_OPTIMIZED_HTML, | String::UL_HTML|String::UL_OPTIMIZE_BIT, |
| false /* status_allowed */); | false /* status_allowed */); |
| // some root-controlled location | // some root-controlled location |
| Line 356 void real_parser_handler(Pool& pool, LPE | Line 323 void real_parser_handler(Pool& pool, LPE |
| "%s/%s", | "%s/%s", |
| root_config_path, CONFIG_FILE_NAME); | root_config_path, CONFIG_FILE_NAME); |
| // beside by binary | |
| static char site_config_path[MAX_STRING]; | |
| strncpy(site_config_path, argv0, MAX_STRING-1); site_config_path[MAX_STRING-1]=0; // filespec of my binary | |
| if(!( | |
| rsplit(site_config_path, '/') || | |
| rsplit(site_config_path, '\\'))) { // strip filename | |
| // no path, just filename | |
| site_config_path[0]='.'; site_config_path[1]=0; | |
| } | |
| char site_config_filespec[MAX_STRING]; | |
| snprintf(site_config_filespec, MAX_STRING, | |
| "%s/%s", | |
| site_config_path, CONFIG_FILE_NAME); | |
| // process the request | // process the request |
| request.core( | request.core( |
| root_config_filespec, false/*may be abcent*/, // /path/to/admin/auto.p | root_config_filespec, false /*don't fail_on_read_problem*/, // /path/to/admin/parser3.conf |
| 0/*parser_site_auto_path*/, false, // /path/to/site/auto.p | site_config_filespec, false /*don't fail_on_read_problem*/, // /path/to/site/parser3.conf |
| header_only); | header_only); |
| } | } |
| Line 401 DWORD WINAPI HttpExtensionProc(LPEXTENSI | Line 382 DWORD WINAPI HttpExtensionProc(LPEXTENSI |
| }; | }; |
| pool.set_context(&ctx);// no allocations before this line! | pool.set_context(&ctx);// no allocations before this line! |
| #ifdef XML | |
| /** | |
| * Initialize Xerces and Xalan. | |
| * | |
| * Should be called only once per process before making | |
| * any other API calls. | |
| */ | |
| //_asm int 3; | |
| XalanInitialize(); | |
| pool.register_cleanup(callXalanTerminate, 0); | |
| #endif | |
| bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0; | bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0; |
| try { // global try | try { // global try |
| call_real_parser_handler__do_SEH(pool, lpECB, header_only); | call_real_parser_handler__do_SEH(pool, lpECB, header_only); |
| Line 456 DWORD WINAPI HttpExtensionProc(LPEXTENSI | Line 424 DWORD WINAPI HttpExtensionProc(LPEXTENSI |
| // unsuccessful finish | // unsuccessful finish |
| } | } |
| /* | |
| const char *body="test"; | |
| // | |
| int content_length=strlen(body); | |
| // 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\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; | |
| 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 | |
| lpECB->dwHttpStatusCode=200; | |
| lpECB->ServerSupportFunction(lpECB->ConnID, | |
| HSE_REQ_SEND_RESPONSE_HEADER_EX, &header_info, NULL, NULL); | |
| // send body | |
| DWORD num_bytes=content_length; | |
| lpECB->WriteClient(lpECB->ConnID, | |
| (void *)body, &num_bytes, HSE_IO_SYNC); | |
| */ | |
| return HSE_STATUS_SUCCESS_AND_KEEP_CONN; | return HSE_STATUS_SUCCESS_AND_KEEP_CONN; |
| } | } |
| BOOL WINAPI DllMain( | |
| HINSTANCE hinstDLL, // handle to the DLL module | |
| DWORD fdwReason, // reason for calling function | |
| LPVOID lpvReserved // reserved | |
| ) { | |
| GetModuleFileName( | |
| hinstDLL, // handle to module | |
| argv0, // file name of module | |
| sizeof(argv0) // size of buffer | |
| ); | |
| return TRUE; | |
| } | |