Author: wrowe
Date: Sun Jan  2 13:09:56 2005
New Revision: 123900

URL: http://svn.apache.org/viewcvs?view=rev&rev=123900
Log:

  Fix logging by injecting the correct server rec throughout the inital
  configuration phase.  Also adapt a new global_conf cor_version variable
  for tracking the .NET flavor (to become a config directive in a later
  patch.)
Modified:
   httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp

Modified: httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp
Url: 
http://svn.apache.org/viewcvs/httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp?view=diff&rev=123900&p1=httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp&r1=123899&p2=httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp&r2=123900
==============================================================================
--- httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp     (original)
+++ httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp     Sun Jan  2 13:09:56 2005
@@ -81,6 +81,7 @@
     IApacheWebHostFactory *pHostFactory;
     HMODULE lock_module;
     OSVERSIONINFO osver;
+    char *cor_version;
 } *global_conf;
 
 // Initialized for each restart
@@ -129,7 +130,7 @@
                                          APR_FILEPATH_TRUENAME, cmd->pool);
 
     if (rv != APR_SUCCESS || !root) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server,
                      "mod_aspdotnet: Failed to resolve the full file path"
                      "for AspNetMount \"%s\" \"%s\"", uri, rootarg);
         return NULL;
@@ -138,9 +139,9 @@
     apr_finfo_t fi;
     rv = apr_stat(&fi, root, APR_FINFO_TYPE, cmd->temp_pool);
     if ((rv != APR_SUCCESS) || (fi.filetype != APR_DIR)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
-            "mod_aspdotnet: File path is a directory, or could not stat path "
-                     "for AspNetMount \"%s\" \"%s\"", uri, rootarg);
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server,
+            "mod_aspdotnet: File path is not a directory, or could not stat "
+                     "path for AspNetMount \"%s\" \"%s\"", uri, rootarg);
         return NULL;
     }
 
@@ -201,7 +202,7 @@
     return APR_SUCCESS;
 }
 
-static void asp_module_lock98(void)
+static void asp_module_lock98(server_rec *global_server)
 {
     // Get the path to this mod_aspdotnet module so that we can
     // lock ourselves in-place for the lifetime of the server
@@ -209,8 +210,7 @@
     HMODULE hModule = GetModuleHandleA("mod_aspdotnet.so");
     if (!GetModuleFileNameA(hModule, AspNetPath, APR_PATH_MAX)) {
         HRESULT hr = GetLastError();
-        apr_status_t rv = APR_FROM_OS_ERROR(hr);
-        ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Failed to discover the full file path to "
                      "mod_aspdotnet.so.  (Was it renamed?)");
         _com_raise_error(hr);
@@ -220,7 +220,7 @@
     global_conf->lock_module = LoadLibraryA(AspNetPath);
 }
 
-static void asp_module_lock(void)
+static void asp_module_lock(server_rec *global_server)
 {
     // Get the path to this mod_aspdotnet module so that we can
     // lock ourselves in-place for the lifetime of the server
@@ -228,8 +228,7 @@
     HMODULE hModule = GetModuleHandleW(L"mod_aspdotnet.so");
     if (!GetModuleFileNameW(hModule, wAspNetPath, APR_PATH_MAX)) {
         HRESULT hr = GetLastError();
-        apr_status_t rv = APR_FROM_OS_ERROR(hr);
-        ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Failed to discover the full file path to "
                      "mod_aspdotnet.so.  (Was it renamed?)");
         _com_raise_error(hr);
@@ -239,15 +238,15 @@
     global_conf->lock_module = LoadLibraryW(wAspNetPath);
 }
 
-static HRESULT init_asp_engine(void)
+static HRESULT init_asp_engine(server_rec *global_server)
 {
-    global_conf->osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    global_conf->osver.dwOSVersionInfoSize = sizeof(global_conf->osver);
     GetVersionEx(&(global_conf->osver));
 
     if (global_conf->osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
-        asp_module_lock98();
+        asp_module_lock98(global_server);
     else
-        asp_module_lock();
+        asp_module_lock(global_server);
 
     // Now we are prepared to register our cleanup in the global
     // process pool, because we trust the module cannot be unloaded
@@ -255,20 +254,30 @@
     apr_pool_cleanup_register(global_conf->pool, NULL, asp_net_stop, 
                               apr_pool_cleanup_null);
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, global_server,
                 "mod_aspdotnet: Module initialization commencing...");
 
-    wchar_t wCORVersion[APR_PATH_MAX];
-    DWORD len;
     HRESULT hr;
-    hr = GetCORVersion(wCORVersion, sizeof(wCORVersion) 
-                                     / sizeof(WCHAR) - 1, &len);
-    if (FAILED(hr)) {
-        wCORVersion[len] = L'\0';
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
-                     "mod_aspdotnet: GetCORVersion failed to return "
-                     "the .NET CLR engine version.");
-        _com_raise_error(hr);
+    wchar_t wCORVersion[256];
+    if (global_conf->cor_version) {
+        MultiByteToWideChar(CP_UTF8, 0, global_conf->cor_version, -1,
+                            wCORVersion, sizeof(wCORVersion) / 
sizeof(wchar_t));
+    }
+    else {
+        DWORD bytes;
+        hr = GetCORVersion(wCORVersion, sizeof(wCORVersion) 
+                                          / sizeof(wchar_t) - 1, &bytes);
+        if (FAILED(hr)) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
+                        "mod_aspdotnet: GetCORVersion failed to return "
+                        "the .NET CLR engine version.");
+            _com_raise_error(hr);
+        }
+        int len = WideCharToMultiByte(CP_UTF8, 0, wCORVersion, -1, 
+                                      NULL, 0, NULL, NULL);
+        global_conf->cor_version = (char *)apr_palloc(global_conf->pool, len);
+        len = WideCharToMultiByte(CP_UTF8, 0, wCORVersion, -1, 
+                                  global_conf->cor_version, len, NULL, NULL);
     }
 
     hr = CorBindToRuntimeEx(wCORVersion, 
@@ -279,33 +288,37 @@
                             IID_ICorRuntimeHost, 
                             (void **)&global_conf->pCorRuntime);
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
-                     "mod_aspdotnet: Could not CorBindToRuntimeEx "
-                     "for the .NET CLR engine.");
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
+                     "mod_aspdotnet: Could not CorBindToRuntimeEx version "
+                     "%s for the .NET CLR engine.", global_conf->cor_version);
         _com_raise_error(hr);
     }
 
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, global_server,
+                 "mod_aspdotnet: CorBindToRuntimeEx loaded version "
+                 "%s of the .NET CLR engine.", global_conf->cor_version);
+
     hr = global_conf->pCorRuntime->Start();
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not start the "
                      ".NET CLR engine.");
         _com_raise_error(hr);
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, global_server,
                  "mod_aspdotnet: Module started .NET CLR...");
 
     IUnknown *pAppDomainIUnk = NULL;
     hr = global_conf->pCorRuntime->GetDefaultDomain(&pAppDomainIUnk);
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the .NET default "
                      "application domain.");
         _com_raise_error(hr);
     }
     if (!pAppDomainIUnk) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the .NET default "
                      "application domain's interface.");
         _com_raise_error(E_NOINTERFACE);
@@ -318,19 +331,19 @@
     pAppDomainIUnk->Release();
 
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the .NET default "
                      "application domain's _AppDomain interface.");
         _com_raise_error(hr);
     }
     if (!pDefaultDomain) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the .NET default "
                      "application domain _AppDomain interface.");
         _com_raise_error(E_NOINTERFACE);
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, global_server,
                  "mod_aspdotnet: Module initialized .NET default 
AppDomain...");
 
     _ObjectHandle *pObjHandle = NULL;
@@ -344,13 +357,13 @@
     pDefaultDomain->Release();
 
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not create the .NET interface "
                      "for the Apache.Web.HostFactory.");
         _com_raise_error(hr);
     }
     if (!pObjHandle) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the .NET object "
                      "for the Apache.Web.HostFactory.");
         _com_raise_error(E_NOINTERFACE);
@@ -360,13 +373,13 @@
     VariantInit(&vHostFactory);
     hr = pObjHandle->Unwrap(&vHostFactory);
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not unwrap the COM interface "
                      "for the Apache.Web.HostFactory.");
         _com_raise_error(hr);
     }
     if (!vHostFactory.pdispVal) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the unknown COM "
                      "interface for the Apache.Web.HostFactory.");
         _com_raise_error(E_NOINTERFACE);
@@ -378,25 +391,25 @@
     VariantClear(&vHostFactory);
 
     if (FAILED(hr)) { 
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not retrieve the COM interface "
                      "for the Apache.Web.HostFactory.");
         _com_raise_error(hr);
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, global_server,
                  "mod_aspdotnet: Module initialized HostFactory...");
 
     // Test invocation, assure we have a good hostfactory
     hr = global_conf->pHostFactory->Configure(L"");
     if (FAILED(hr)) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), NULL,
+        ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                      "mod_aspdotnet: Could not correctly configure the "
                      "Apache.Web.HostFactory.");
         _com_raise_error(hr);
     }
 
-    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
+    ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, global_server,
                  "mod_aspdotnet: HostFactory configuration complete.");
 
     return S_OK;
@@ -530,16 +543,7 @@
     // we do not want to repeat this twice per Apache process.
     if ((apr_pool_userdata_get((void**)&global_conf, 
"mod_aspdotnet::global_conf", 
                                process) != APR_SUCCESS) || !global_conf) {
-        HRESULT hr = CoInitialize(NULL);
-        if (hr == RPC_E_CHANGED_MODE)
-            hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
-        if (FAILED(hr)) {
-            ap_log_error(APLOG_MARK, APLOG_CRIT, APR_FROM_OS_ERROR(hr), NULL,
-                        "mod_aspdotnet: Failed to CoInitialize the threaded "
-                        "COM engine for .NET CLR interop!");
-            return 1;
-        }
-        global_conf = (asp_net_conf_t*)apr_palloc(process, 
sizeof(*global_conf));
+        global_conf = (asp_net_conf_t*)apr_pcalloc(process, 
sizeof(*global_conf));
         global_conf->pool  = process;
         global_conf->hosts = apr_hash_make(process);
         global_conf->pCorRuntime  = NULL;
@@ -552,7 +556,7 @@
 
 
 static int asp_net_post_config(apr_pool_t *pconf, apr_pool_t *plog, 
-                               apr_pool_t *ptemp, server_rec *gs)
+                               apr_pool_t *ptemp, server_rec *global_server)
 {
     apr_hash_index_t *item;
 
@@ -563,30 +567,39 @@
 
     // First time through, initialize .Net and the HostFactory
     if (!global_conf->pCorRuntime || !global_conf->pHostFactory) {
+        HRESULT hr = CoInitialize(NULL);
+        if (hr == RPC_E_CHANGED_MODE)
+            hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+        if (FAILED(hr)) {
+            ap_log_error(APLOG_MARK, APLOG_CRIT, APR_FROM_OS_ERROR(hr), 
global_server,
+                        "mod_aspdotnet: Failed to CoInitialize the threaded "
+                        "COM engine for .NET CLR interop!");
+            return 1;
+        }
         try {
-            init_asp_engine();
+            init_asp_engine(global_server);
         }
         catch (_com_error err) {
             char *desc = (char*)err.Description();
             ap_log_error(APLOG_MARK, APLOG_CRIT, 
-                         APR_FROM_OS_ERROR(err.Error()), gs,
+                         APR_FROM_OS_ERROR(err.Error()), global_server,
                          "mod_aspdotnet: Failed to start Asp.Net "
                          "Apache.Web host factory");
             if (desc) {
                 ap_log_error(APLOG_MARK, APLOG_CRIT, 
-                            APR_FROM_OS_ERROR(err.Error()), gs,
+                            APR_FROM_OS_ERROR(err.Error()), global_server,
                             "mod_aspdotnet: %s", desc);
             }
             return 1;
         }
         catch (HRESULT hr) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), gs,
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                          "mod_aspdotnet: Failed to start Asp.Net "
                          "Apache.Web host factory.");
             return 1;
         }
         catch (...) {
-            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, gs,
+            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, global_server,
                          "mod_aspdotnet: Failed to start Asp.Net "
                          "Apache.Web host factory.");
             return 1;
@@ -635,34 +648,34 @@
 
         try {
             host->host_key = global_conf->pHostFactory->CreateHost(
-                                       virtual_path, physical_path, (UINT_PTR) 
gs);
+                                       virtual_path, physical_path, (UINT_PTR) 
global_server);
             if (host->host_key == -1)
                 _com_raise_error(E_NOINTERFACE);
         }
         catch (_com_error err) {
             ap_log_error(APLOG_MARK, APLOG_CRIT, 
-                         APR_FROM_OS_ERROR(err.Error()), gs, 
+                         APR_FROM_OS_ERROR(err.Error()), global_server, 
                          "mod_aspdotnet: Failed to create Host connector "
                          "for %s mapped to %s", host->virtual_path, 
                          host->physical_path);
             ap_log_error(APLOG_MARK, APLOG_CRIT, 
-                         APR_FROM_OS_ERROR(err.Error()), gs, 
+                         APR_FROM_OS_ERROR(err.Error()), global_server, 
                          "mod_aspdotnet: %s", (char*)err.Description());
             return 1;
         }
         catch (HRESULT hr) {
-            ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), gs,
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), 
global_server,
                          "mod_aspdotnet: Failed to create Host for %s mapped "
                          "to %s", host->virtual_path, host->physical_path);
             return 1;
         }
         catch (...) {
-            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, gs,
+            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, global_server,
                          "mod_aspdotnet: Failed to create Host for %s mapped "
                          "to %s", host->virtual_path, host->physical_path);
             return 1;
         }
-        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, gs,
+        ap_log_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, 0, global_server,
                          "mod_aspdotnet: Sucessfully created Host for %s 
mapped "
                          "to %s", host->virtual_path, host->physical_path);
     }

Reply via email to