Diff for /parser3/src/targets/isapi/parser3isapi.C between versions 1.26 and 1.44

version 1.26, 2001/04/09 15:49:03 version 1.44, 2001/09/26 10:32:26
Line 1 Line 1
   /** @file
           Parser: IIS extension.
   
           Copyright (c) 2000,2001 ArtLebedev Group (http://www.artlebedev.com)
           Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
   
           $Id$
   */
   
 #ifndef _MSC_VER  #ifndef _MSC_VER
 #       error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)]  #       error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)]
 #endif  #endif
   
   #include "pa_config_includes.h"
   
 #include <windows.h>  #include <windows.h>
 #include <process.h>  #include <process.h>
   
Line 13 Line 24
 #include "pa_version.h"  #include "pa_version.h"
 #include "pool_storage.h"  #include "pool_storage.h"
 #include "pa_socks.h"  #include "pa_socks.h"
 #include "pa_exec.h"  
   
 /// @todo init_socks  
   
 #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")  #define MAX_STATUS_LENGTH sizeof("xxxx LONGEST STATUS DESCRIPTION")
   
   // consts
   
   extern const char *main_RCSIds[];
   extern const char *smtp_RCSIds[];
   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,
           smtp_RCSIds,
           gd_RCSIds,
           classes_RCSIds,
           types_RCSIds,
           parser3isapi_RCSIds,
           0
   };
   
 // SAPI  // SAPI
   
 /**   #ifndef DOXYGEN
   /*
         ISAPI SAPI functions receive this context information.           ISAPI SAPI functions receive this context information. 
           see Pool::set_context
         @see Pool::set_context  
 */  */
 struct SAPI_func_context {  struct SAPI_func_context {
         LPEXTENSION_CONTROL_BLOCK lpECB;          LPEXTENSION_CONTROL_BLOCK lpECB;
         String *header;          String *header;
         DWORD http_response_code;          DWORD http_response_code;
 };  };
   #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, ...) {
Line 112  void SAPI::add_header_attribute(Pool& po Line 139  void SAPI::add_header_attribute(Pool& po
                 ctx.header->APPEND_CONST(key);                  ctx.header->APPEND_CONST(key);
                 ctx.header->APPEND_CONST(": ");                  ctx.header->APPEND_CONST(": ");
                 ctx.header->APPEND_CONST(value);                  ctx.header->APPEND_CONST(value);
                 ctx.header->APPEND_CONST("\n");                  ctx.header->APPEND_CONST("\r\n");
         }          }
 }  }
   
Line 121  void SAPI::send_header(Pool& pool) { Line 148  void SAPI::send_header(Pool& pool) {
         SAPI_func_context& ctx=*static_cast<SAPI_func_context *>(pool.context());          SAPI_func_context& ctx=*static_cast<SAPI_func_context *>(pool.context());
   
         ctx.header->APPEND_CONST(          ctx.header->APPEND_CONST(
                 "expires: Fri, 23 Mar 2001 09:32:23 GMT\n"                  "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n"
                 "\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 161  void SAPI::send_body(Pool& pool, const v Line 188  void SAPI::send_body(Pool& pool, const v
                 const_cast<void *>(buf), &num_bytes, HSE_IO_SYNC);                  const_cast<void *>(buf), &num_bytes, HSE_IO_SYNC);
 }  }
   
 int SAPI::execute(const String& file_spec,   
         const Hash *env,  
         const Array *argv,  
         const String& in, String& out, String& err) {  
         return pa_exec(file_spec, env, argv, in,  out, err);  
 }  
   
 //   // 
   
 static bool parser_init() {  static bool parser_init() {
Line 178  static bool parser_init() { Line 198  static bool parser_init() {
   
         static Pool pool(0); // global pool          static Pool pool(0); // global pool
         PTRY {          PTRY {
                   // init socks
                   init_socks(pool);
   
                   // init global classes
                   init_methoded_array(pool);
                 // init global variables                  // init global variables
                 pa_globals_init(pool);                  pa_globals_init(pool);
                                   
Line 195  static bool parser_init() { Line 220  static bool parser_init() {
 /// ISAPI //  /// ISAPI //
 BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) {  BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer) {
         pVer->dwExtensionVersion = HSE_VERSION;          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();          return parser_init();
 }  }
   
Line 207  BOOL WINAPI GetExtensionVersion(HSE_VERS Line 233  BOOL WINAPI GetExtensionVersion(HSE_VERS
                 to do that we need to consult metabase,                  to do that we need to consult metabase,
                 wich is tested&works but seems slow runtime                   wich is tested&works but seems slow runtime 
                 and not could-be-quickly-implemented if prepared.                  and not could-be-quickly-implemented if prepared.
           @test
                   PARSER_VERSION from outside
 */  */
 DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) {  DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) {
         Pool_storage pool_storage;          Pool_storage pool_storage;
Line 214  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 242  DWORD WINAPI HttpExtensionProc(LPEXTENSI
         SAPI_func_context ctx={          SAPI_func_context ctx={
                 lpECB,                  lpECB,
                 0, // filling later: so that if there would be error pool would have ctx                  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!          pool.set_context(&ctx);// no allocations before this line!
                   
         bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0;          bool header_only=strcasecmp(lpECB->lpszMethod, "HEAD")==0;
Line 236  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 265  DWORD WINAPI HttpExtensionProc(LPEXTENSI
                         // IIS                          // IIS
                         size_t len=strlen(filespec_to_process)-strlen(path_info);                          size_t len=strlen(filespec_to_process)-strlen(path_info);
                         char *buf=(char *)pool.malloc(len+1);                          char *buf=(char *)pool.malloc(len+1);
                         strncpy(buf, filespec_to_process, len);                          strncpy(buf, filespec_to_process, len); buf[len]=0;
                         buf[len]=0;  
                         request_info.document_root=buf;                          request_info.document_root=buf;
                 } else                  } else
                         PTHROW(0, 0,                          PTHROW(0, 0,
Line 267  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 295  DWORD WINAPI HttpExtensionProc(LPEXTENSI
                 // prepare to process request                  // prepare to process request
                 Request request(pool,                  Request request(pool,
                         request_info,                          request_info,
                         String::UL_HTML_TYPO                          String::UL_USER_HTML
                         );                          );
   
                 // some root-controlled location                  // some root-controlled location
                 //   c:\windows                  //   c:\windows
                   char root_config_path[MAX_STRING];
                   GetWindowsDirectory(root_config_path, MAX_STRING);
                 // must be dynamic: rethrowing from request.core                   // must be dynamic: rethrowing from request.core 
                 //   may return 'source' which can be inside of 'root auto.p@exeception'                  //   may return 'source' which can be inside of 'root auto.p@exeception'
                 char *root_auto_path=(char *)pool.malloc(MAX_STRING);                  char *root_config_filespec=(char *)pool.malloc(MAX_STRING);
                 GetWindowsDirectory(root_auto_path, MAX_STRING);                  snprintf(root_config_filespec, MAX_STRING, 
                           "%s/%s", 
                           root_config_path, CONFIG_FILE_NAME);
   
                 // process the request                  // process the request
                 request.core(                  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                          0/*parser_site_auto_path*/, false, // /path/to/site/auto.p
                         header_only);                          header_only);
                 // successful finish                  // successful finish
         } PCATCH(e) { // global problem          } PCATCH(e) { // global problem
                 // don't allocate anything on pool here:                  // don't allocate anything on pool here:
                 //   possible pool' exception not catch-ed now                  //   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();                  const char *body=e.comment();
                 // log it                  // log it
                 SAPI::log(pool, "exception in request exception handler: %s", body);                  SAPI::log(pool, "exception in request exception handler: %s", body);
Line 297  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 329  DWORD WINAPI HttpExtensionProc(LPEXTENSI
                 // prepare header // not using SAPI func wich allocates on pool                  // prepare header // not using SAPI func wich allocates on pool
                 char header_buf[MAX_STRING];                  char header_buf[MAX_STRING];
                 int header_len=snprintf(header_buf, MAX_STRING,                  int header_len=snprintf(header_buf, MAX_STRING,
                         "content-type: text/plain\n"                          "content-type: text/plain\r\n"
                         "content-length: %ul\n"                          "content-length: %lu\r\n"
                         "expires: Fri, 23 Mar 2001 09:32:23 GMT\n"                          "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n"
                         "\n",                          "\r\n",
                         content_length);                          content_length);
   
                 HSE_SEND_HEADER_EX_INFO header_info;                  HSE_SEND_HEADER_EX_INFO header_info;

Removed from v.1.26  
changed lines
  Added in v.1.44


E-mail: