Sync to Wine-20050725:
[reactos.git] / reactos / lib / urlmon / umon.c
index 249d85a..b4d7904 100644 (file)
@@ -51,7 +51,7 @@ static const WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e',
 typedef struct {
     const IBindingVtbl *lpVtbl;
 
-    ULONG ref;
+    LONG ref;
 
     LPWSTR URLName;
 
@@ -291,7 +291,7 @@ typedef struct {
 
     const IMonikerVtbl* lpvtbl;  /* VTable relative to the IMoniker interface.*/
 
-    ULONG ref; /* reference counter for this object */
+    LONG ref; /* reference counter for this object */
 
     LPOLESTR URLName; /* URL string identified by this URLmoniker */
 } URLMonikerImpl;
@@ -340,8 +340,6 @@ static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface)
 
     TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
 
-    URLMON_LockModule();
-
     return refCount;
 }
 
@@ -359,9 +357,9 @@ static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface)
     if (!refCount) {
         HeapFree(GetProcessHeap(),0,This->URLName);
         HeapFree(GetProcessHeap(),0,This);
-    }
 
-    URLMON_UnlockModule();
+        URLMON_UnlockModule();
+    }
 
     return refCount;
 }
@@ -600,7 +598,7 @@ static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
             if(SUCCEEDED(hres)) {
                 WCHAR *urlcopy, *tmpwc;
                 URL_COMPONENTSW url;
-                WCHAR *host, *path, *user, *pass;
+                WCHAR *host, *path, *partial_path, *user, *pass;
                 DWORD lensz = sizeof(bind->expected_size);
                 DWORD dwService = 0;
                 BOOL bSuccess;
@@ -638,7 +636,7 @@ static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
                 memset(&url, 0, sizeof(url));
                 url.dwStructSize = sizeof(url);
                 url.dwSchemeLength = url.dwHostNameLength = url.dwUrlPathLength = url.dwUserNameLength = url.dwPasswordLength = 1;
-                InternetCrackUrlW(urlcopy, 0, 0, &url);
+                InternetCrackUrlW(urlcopy, 0, ICU_ESCAPE, &url);
                 host = HeapAlloc(GetProcessHeap(), 0, (url.dwHostNameLength + 1) * sizeof(WCHAR));
                 memcpy(host, url.lpszHostName, url.dwHostNameLength * sizeof(WCHAR));
                 host[url.dwHostNameLength] = '\0';
@@ -799,9 +797,9 @@ static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
                     break;
 
                 case INTERNET_SCHEME_FILE:
-                    path = bind->URLName + 5; /* Skip the "file:" part */
-                    if ((path[0] != '/' && path[0] != '\\') ||
-                        (path[1] != '/' && path[1] != '\\'))
+                    partial_path = bind->URLName + 5; /* Skip the "file:" part */
+                    if ((partial_path[0] != '/' && partial_path[0] != '\\') ||
+                        (partial_path[1] != '/' && partial_path[1] != '\\'))
                     {
                         hres = E_FAIL;
                     }
@@ -809,10 +807,10 @@ static HRESULT WINAPI URLMonikerImpl_BindToStorage(IMoniker* iface,
                     {
                         HANDLE h;
 
-                        path += 2;
-                        if (path[0] == '/' || path[0] == '\\')
-                            ++path;
-                        h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
+                        partial_path += 2;
+                        if (partial_path[0] == '/' || partial_path[0] == '\\')
+                            ++partial_path;
+                        h = CreateFileW(partial_path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );
                         if (h == (HANDLE) HFILE_ERROR)
                         {
                             hres = HRESULT_FROM_WIN32(GetLastError());
@@ -1136,7 +1134,7 @@ static const IMonikerVtbl VT_URLMonikerImpl =
 static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeftURLName, LPCOLESTR lpszURLName)
 {
     HRESULT hres;
-    DWORD sizeStr;
+    DWORD sizeStr = INTERNET_MAX_URL_LENGTH;
 
     TRACE("(%p,%s,%s)\n",This,debugstr_w(lpszLeftURLName),debugstr_w(lpszURLName));
     memset(This, 0, sizeof(*This));
@@ -1170,6 +1168,8 @@ static HRESULT URLMonikerImpl_Construct(URLMonikerImpl* This, LPCOLESTR lpszLeft
     else
         strcpyW(This->URLName,lpszURLName);
 
+    URLMON_LockModule();
+
     return S_OK;
 }
 
@@ -1255,11 +1255,12 @@ HRESULT WINAPI CreateURLMoniker(IMoniker *pmkContext, LPCWSTR szURL, IMoniker **
        return E_OUTOFMEMORY;
 
     if(pmkContext) {
-        CLSID clsid;
         IBindCtx* bind;
-        IMoniker_GetClassID(pmkContext, &clsid);
-        if(IsEqualCLSID(&clsid, &CLSID_StdURLMoniker) && SUCCEEDED(CreateBindCtx(0, &bind))) {
-            URLMonikerImpl_GetDisplayName(pmkContext, bind, NULL, &lefturl);
+        DWORD dwMksys = 0;
+        IMoniker_IsSystemMoniker(pmkContext, &dwMksys);
+        if(dwMksys == MKSYS_URLMONIKER && SUCCEEDED(CreateBindCtx(0, &bind))) {
+            IMoniker_GetDisplayName(pmkContext, bind, NULL, &lefturl);
+            TRACE("lefturl = %s\n", debugstr_w(lefturl));
             IBindCtx_Release(bind);
         }
     }