Author: wrowe
Date: Fri Nov 26 12:15:49 2004
New Revision: 106658

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

  Close an xxx: note - convert our uri / physical path from utf-8 to
  unicode before passing as BSTR's to CreateHost.

  Since questions have been raised; 'how many times do we map the very
  same vhost to an asp application directory?' record all successes at
  LogLevel Debug.

  Also fix some awkward wording in failure messages.

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=106658&p1=httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp&r1=106657&p2=httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp&r2=106658
==============================================================================
--- httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp     (original)
+++ httpd/mod_aspdotnet/trunk/mod/mod_aspdotnet.cpp     Fri Nov 26 12:15:49 2004
@@ -586,19 +586,46 @@
     for (item = apr_hash_first(ptemp, global_conf->hosts); item; 
             item = apr_hash_next(item)) 
     {
+        wchar_t *path;
+        apr_size_t inlen, outlen;
+        _bstr_t virtual_path, physical_path;
         asp_net_host_conf_t *host;
         apr_hash_this(item, NULL, NULL, (void**)&host);
-    
+
+        // Initialize each host mapping, only once.
         if (host->host_key != -1) {
             continue;
         }
 
+        // Treat AspNetMount paths as utf-8 strings, fail over to
+        // default _bstr_t multibyte conversion if unconvertable.
+        // Relies on simple utf-8 -> unicode rule, that output will
+        // never be more wchar's than the number of input chars.
+        inlen = strlen(host->virtual_path) + 1;
+        path = (wchar_t*)apr_palloc(ptemp, inlen * 2);
+        outlen = MultiByteToWideChar(CP_UTF8, 0, host->virtual_path, 
+                                     inlen, path, inlen);
+        if (outlen) {
+            virtual_path = path;
+        }
+        else {
+            virtual_path = host->virtual_path;
+        }
+
+        inlen = strlen(host->physical_path) + 1;
+        path = (wchar_t*)apr_palloc(ptemp, inlen * 2);
+        outlen = MultiByteToWideChar(CP_UTF8, 0, host->physical_path, 
+                                     inlen, path, inlen);
+        if (outlen) {
+            physical_path = path;
+        }
+        else {
+            physical_path = host->physical_path;
+        }
+
         try {
-            // XXX: i18n these paths by treating them as UTF-8 -> Unicode!!!
             host->host_key = global_conf->pHostFactory->CreateHost(
-                                                 _bstr_t(host->virtual_path), 
-                                                 _bstr_t(host->physical_path),
-                                                 (int) gs);
+                                       virtual_path, physical_path, (int) gs);
             if (host->host_key == -1)
                 _com_raise_error(E_NOINTERFACE);
         }
@@ -615,16 +642,19 @@
         }
         catch (HRESULT hr) {
             ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(hr), gs,
-                         "mod_aspdotnet: Failed to create Host of for %s 
mapped "
+                         "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,
-                         "mod_aspdotnet: Failed to create Host of for %s 
mapped "
+                         "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,
+                         "mod_aspdotnet: Sucessfully created Host for %s 
mapped "
+                         "to %s", host->virtual_path, host->physical_path);
     }
 
     return OK;

Reply via email to