Diff for /parser3/src/targets/isapi/parser3isapi.C between versions 1.63 and 1.71

version 1.63, 2002/02/08 08:30:18 version 1.71, 2002/05/07 07:39:19
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(          HSE_SEND_HEADER_EX_INFO header_info;
                 "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];          char status_buf[MAX_STATUS_LENGTH];
         switch(ctx.http_response_code) {          switch(ctx.http_response_code) {
Line 210  void SAPI::send_header(Pool& pool) { Line 189  void SAPI::send_header(Pool& pool) {
                         break;                          break;
         }          }
         header_info.cchStatus=strlen(header_info.pszStatus);          header_info.cchStatus=strlen(header_info.pszStatus);
           *ctx.header << "\r\n"; // ISAPI v<5 did quite well without it
         header_info.pszHeader=ctx.header->cstr();          header_info.pszHeader=ctx.header->cstr();
         header_info.cchHeader=ctx.header->size();          header_info.cchHeader=ctx.header->size();
         header_info.fKeepConn=true;          header_info.fKeepConn=true;
Line 235  int failed_new(size_t size) { Line 215  int failed_new(size_t size) {
         return 0; // not reached          return 0; // not reached
 }  }
   
   #ifdef _DEBUG
   static Pool_storage *global_pool_storagep;
   #endif
 static bool parser_init() {  static bool parser_init() {
         static bool globals_inited=false;          static bool globals_inited=false;
         if(globals_inited)          if(globals_inited)
Line 243  static bool parser_init() { Line 226  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;
   #ifdef _DEBUG
           global_pool_storagep=&pool_storage;
   #endif
           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 315  void real_parser_handler(Pool& pool, LPE Line 289  void real_parser_handler(Pool& pool, LPE
                 strncpy(buf, filespec_to_process, len); buf[len]=0;                  strncpy(buf, filespec_to_process, len); buf[len]=0;
                 request_info.document_root=buf;                  request_info.document_root=buf;
         } else          } else
                 throw Exception(0, 0,                  throw Exception("parser.runtime",
                         0,                          0,
                         "ISAPI: no PATH_INFO defined (in reinventing DOCUMENT_ROOT)");                          "ISAPI: no PATH_INFO defined (in reinventing DOCUMENT_ROOT)");
   
Line 343  void real_parser_handler(Pool& pool, LPE Line 317  void real_parser_handler(Pool& pool, LPE
         Request request(pool,          Request request(pool,
                 request_info,                  request_info,
                 String::UL_HTML|String::UL_OPTIMIZE_BIT,                  String::UL_HTML|String::UL_OPTIMIZE_BIT,
                 false /* status_allowed */);  #ifdef _DEBUG
                   true
   #else
                   false 
   #endif
                           /* status_allowed */);
   
         // some root-controlled location          // some root-controlled location
         //   c:\windows          //   c:\windows
Line 356  void real_parser_handler(Pool& pool, LPE Line 335  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 /*fail_on_read_problem*/, // /path/to/root/parser3.conf
                 0/*parser_site_auto_path*/, false, // /path/to/site/auto.p                  site_config_filespec, false /*fail_on_read_problem*/, // /path/to/site/parser3.conf
                 header_only);                  header_only);
 }  }
   
Line 379  void call_real_parser_handler__do_SEH(Po Line 372  void call_real_parser_handler__do_SEH(Po
                                   
                 if(system_exception)                  if(system_exception)
                         if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord)                          if(_EXCEPTION_RECORD *er=system_exception->ExceptionRecord)
                                 throw Exception(0, 0,                                  throw Exception(0,
                                 0,                                  0,
                                 "Exception 0x%08X at 0x%08X", er->ExceptionCode,  er->ExceptionAddress);                                  "Exception 0x%08X at 0x%08X", er->ExceptionCode,  er->ExceptionAddress);
                         else                          else
                                 throw Exception(0, 0, 0, "Exception <no exception record>");                                  throw Exception(0, 0, "Exception <no exception record>");
                         else                          else
                                 throw Exception(0, 0, 0, "Exception <no exception information>");                                  throw Exception(0, 0, "Exception <no exception information>");
         }          }
 #endif  #endif
 }  }
   
   inline DWORD RealHttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) {
 DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) {  
         Pool_storage pool_storage;          Pool_storage pool_storage;
         Pool pool(&pool_storage); // no allocations until assigned context [for reporting]          Pool pool(&pool_storage); // no allocations until assigned context [for reporting]
         SAPI_func_context ctx={          SAPI_func_context ctx={
Line 400  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 392  DWORD WINAPI HttpExtensionProc(LPEXTENSI
                 200 // default http_response_code                  200 // default http_response_code
         };          };
         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
Line 434  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 413  DWORD WINAPI HttpExtensionProc(LPEXTENSI
                 int header_len=snprintf(header_buf, MAX_STRING,                  int header_len=snprintf(header_buf, MAX_STRING,
                         "content-type: text/plain\r\n"                          "content-type: text/plain\r\n"
                         "content-length: %lu\r\n"                          "content-length: %lu\r\n"
                         "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n"  //                      "expires: Fri, 23 Mar 2001 09:32:23 GMT\r\n"
                         "\r\n",                          "\r\n",
                         content_length);                          content_length);
   
Line 456  DWORD WINAPI HttpExtensionProc(LPEXTENSI Line 435  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;
 }  }
   
   #ifdef _DEBUG
   //for memory leaks detection only
   #undef _WINDOWS_
   #include <afx.h>
   #endif
   DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB) {
   // Declare the variables needed
   #ifdef _DEBUG
   //      _crtBreakAlloc=97779;//97777; //997;
   
       CMemoryState oldMemState, newMemState, diffMemState;
       oldMemState.Checkpoint();
           //global_pool_storagep->fbreak_on_alloc=true;
   #endif
           
           DWORD result=RealHttpExtensionProc(lpECB);
   
   #ifdef _DEBUG
       newMemState.Checkpoint();
       if( diffMemState.Difference( oldMemState, newMemState ) )
       {
           TRACE( "Memory leaked!\n" );
                   diffMemState.DumpStatistics( );
                   diffMemState.DumpAllObjectsSince();
       }
   #endif
           return result;
   }
   
   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;
   }
   

Removed from v.1.63  
changed lines
  Added in v.1.71


E-mail: