[PATCH 4/4] url: Implement TranslateURL

Detlef Riekenberg wine.dev at web.de
Tue Aug 26 03:47:42 CDT 2008


---
 dlls/url/url.spec   |    4 +-
 dlls/url/url_main.c |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/dlls/url/url.spec b/dlls/url/url.spec
index cedd9e4..465e2e4 100644
--- a/dlls/url/url.spec
+++ b/dlls/url/url.spec
@@ -17,7 +17,7 @@
 @ stub OpenURLA
 @ stdcall TelnetProtocolHandler(long str) TelnetProtocolHandlerA
 @ stdcall TelnetProtocolHandlerA(long str)
-@ stub TranslateURLA
-@ stub TranslateURLW
+@ stdcall TranslateURLA(str long ptr)
+@ stdcall TranslateURLW(wstr long ptr)
 @ stub URLAssociationDialogA
 @ stub URLAssociationDialogW
diff --git a/dlls/url/url_main.c b/dlls/url/url_main.c
index 69b46ea..5e2ab26 100644
--- a/dlls/url/url_main.c
+++ b/dlls/url/url_main.c
@@ -1,5 +1,6 @@
 /*
  * Copyright 2006 Alexandre Julliard
+ * Copyright 2006,2008 Detlef Riekenberg
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,9 +22,11 @@
 #include "winbase.h"
 #include "winreg.h"
 #include "winerror.h"
+#include "winnls.h"
 #include "shellapi.h"
 #include "shlwapi.h"
 #include "intshcut.h"
+#include "wininet.h"
 #include "winuser.h"
 #include "commctrl.h"
 #include "prsht.h"
@@ -116,3 +119,95 @@ HRESULT WINAPI TelnetProtocolHandlerA(HWND hWnd, LPSTR lpStr)
 
     return E_NOTIMPL;
 }
+
+/***********************************************************************
+ * TranslateURLW (URL.@)
+ *
+ * Apply URL Scheme, when needed
+ *
+ * PARAMS
+ *  pURL            [I] URL, that needs to be translated
+ *  dwFlags         [I] Flags to control the translation
+ *  ppTranslatedURL [O] Pointer, where the stringpointer of the result is returned
+ *
+ * RESULTS
+ *  Success: S_OK and in pTranslatedURL the pointer of the translated URL
+ *  Failure: An HRESULT error code describing the error
+ *
+ * NOTES
+ *  The returned String must be freed with LocalFree
+ *
+ */
+
+HRESULT WINAPI TranslateURLW(LPCWSTR pURL, DWORD dwFlags, LPWSTR * ppTranslatedURL)
+{
+    HRESULT res;
+    WCHAR newurl[INTERNET_MAX_URL_LENGTH];
+    DWORD newflags = 0;
+    DWORD len;
+
+    TRACE("(%s, 0x%x, %p)\n", debugstr_w(pURL), dwFlags, ppTranslatedURL);
+
+    if (ppTranslatedURL) *ppTranslatedURL = NULL;
+    if (!pURL || !ppTranslatedURL) {
+        return E_POINTER;
+    }
+
+    if (dwFlags &= ~(TRANSLATEURL_FL_GUESS_PROTOCOL | TRANSLATEURL_FL_USE_DEFAULT_PROTOCOL)) {
+        TRACE("Undocumented Flags: 0x%x\n", dwFlags &
+             ~(TRANSLATEURL_FL_GUESS_PROTOCOL | TRANSLATEURL_FL_USE_DEFAULT_PROTOCOL));
+        return E_FLAGS;
+    }
+
+    if (dwFlags & TRANSLATEURL_FL_GUESS_PROTOCOL) {
+        newflags |= URL_APPLY_GUESSSCHEME;
+    }
+    if (dwFlags & TRANSLATEURL_FL_USE_DEFAULT_PROTOCOL) {
+        newflags |= (URL_APPLY_DEFAULT);
+    }
+
+    len = INTERNET_MAX_URL_LENGTH;
+
+    res = UrlApplySchemeW(pURL, newurl, &len, newflags);
+    if (res == S_OK) {
+        *ppTranslatedURL = LocalAlloc(LMEM_FIXED, (len + 1) * sizeof(WCHAR));
+        lstrcpyW(*ppTranslatedURL, newurl);
+    }
+
+    TRACE("=> 0x%x / %s\n", res, (res == S_OK) ? debugstr_w(*ppTranslatedURL) : "");
+    return res;
+}
+
+/***********************************************************************
+ * TranslateURLA (URL.@)
+ *
+ * See TranslateURLW
+ *
+ */
+
+HRESULT WINAPI TranslateURLA(LPCSTR pURL, DWORD dwFlags, LPSTR * ppTranslatedURL)
+{
+    LPWSTR urlW = NULL;
+    HRESULT res;
+    INT len;
+
+    TRACE("(%s, 0x%x, %p)\n", debugstr_a(pURL), dwFlags, ppTranslatedURL);
+    if (pURL) {
+        len = MultiByteToWideChar(CP_ACP, 0, pURL, -1, NULL, 0);
+        urlW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+        MultiByteToWideChar(CP_ACP, 0, pURL, -1, urlW, len);
+    }
+
+    res = TranslateURLW(urlW, dwFlags, (LPWSTR *) ppTranslatedURL);
+    HeapFree(GetProcessHeap(), 0, urlW);
+
+    urlW = * ((LPWSTR*) ppTranslatedURL);
+    if ((res == S_OK) && urlW) {
+        len = WideCharToMultiByte(CP_ACP, 0, urlW, -1, NULL, 0, NULL, NULL);
+        *ppTranslatedURL = LocalAlloc(LMEM_FIXED, len);
+        WideCharToMultiByte(CP_ACP, 0, urlW, -1, * ppTranslatedURL, len, NULL, NULL);
+        LocalFree(urlW);
+    }
+    return res;
+}
+ 
-- 
1.5.4.3


--=-4dy8vKbdA2lyWlkWGe8X--




More information about the wine-patches mailing list