Module: wine Branch: master Commit: 6e4ead77a73190b3c7285b04bc90a6955ee91af0 URL: http://source.winehq.org/git/wine.git/?a=commit;h=6e4ead77a73190b3c7285b04bc...
Author: Thomas Mullaly thomas.mullaly@gmail.com Date: Sat Aug 7 02:06:31 2010 -0400
urlmon: Implemented CreateUriWithFragment.
---
dlls/urlmon/tests/uri.c | 40 ++++++++++++++--------------------- dlls/urlmon/uri.c | 52 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 26 deletions(-)
diff --git a/dlls/urlmon/tests/uri.c b/dlls/urlmon/tests/uri.c index 83aa433..88f89db 100644 --- a/dlls/urlmon/tests/uri.c +++ b/dlls/urlmon/tests/uri.c @@ -3715,21 +3715,21 @@ typedef struct _uri_with_fragment {
static const uri_with_fragment uri_fragment_tests[] = { { - "http://google.com/%22,%22#fragment%22,0,S_OK,TRUE, - "http://google.com/#fragment%22,TRUE + "http://google.com/%22,%22#fragment%22,0,S_OK,FALSE, + "http://google.com/#fragment%22,FALSE }, { - "http://google.com/%22,%22fragment%22,0,S_OK,TRUE, - "http://google.com/#fragment%22,TRUE + "http://google.com/%22,%22fragment%22,0,S_OK,FALSE, + "http://google.com/#fragment%22,FALSE }, { - "zip://test.com/","?test",0,S_OK,TRUE, - "zip://test.com/#?test",TRUE + "zip://test.com/","?test",0,S_OK,FALSE, + "zip://test.com/#?test",FALSE }, /* The fragment can be empty. */ { - "ftp://ftp.google.com/","",0,S_OK,TRUE, - "ftp://ftp.google.com/#",TRUE + "ftp://ftp.google.com/","",0,S_OK,FALSE, + "ftp://ftp.google.com/#",FALSE } };
@@ -4802,23 +4802,17 @@ static void test_CreateUriWithFragment_InvalidArgs(void) { const WCHAR fragmentW[] = {'#','f','r','a','g','m','e','n','t',0};
hr = pCreateUriWithFragment(NULL, fragmentW, 0, 0, &uri); - todo_wine { - ok(hr == E_INVALIDARG, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG); - } - todo_wine { ok(uri == NULL, "Error: Expected uri to be NULL, but was %p instead.\n", uri); } + ok(hr == E_INVALIDARG, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG); + ok(uri == NULL, "Error: Expected uri to be NULL, but was %p instead.\n", uri);
hr = pCreateUriWithFragment(http_urlW, fragmentW, 0, 0, NULL); - todo_wine { - ok(hr == E_INVALIDARG, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG); - } + ok(hr == E_INVALIDARG, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG);
/* Original URI can't already contain a fragment component. */ uri = (void*) 0xdeadbeef; hr = pCreateUriWithFragment(http_url_fragW, fragmentW, 0, 0, &uri); - todo_wine { - ok(hr == E_INVALIDARG, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG); - } - todo_wine { ok(uri == NULL, "Error: Expected uri to be NULL, but was %p instead.\n", uri); } + ok(hr == E_INVALIDARG, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x.\n", hr, E_INVALIDARG); + ok(uri == NULL, "Error: Expected uri to be NULL, but was %p instead.\n", uri); }
/* CreateUriWithFragment has the same invalid flag combinations as CreateUri. */ @@ -4830,11 +4824,9 @@ static void test_CreateUriWithFragment_InvalidFlags(void) { IUri *uri = (void*) 0xdeadbeef;
hr = pCreateUriWithFragment(http_urlW, NULL, invalid_flag_tests[i].flags, 0, &uri); - todo_wine { - ok(hr == invalid_flag_tests[i].expected, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x. flags=0x%08x.\n", - hr, invalid_flag_tests[i].expected, invalid_flag_tests[i].flags); - } - todo_wine { ok(uri == NULL, "Error: Expected uri to be NULL, but was %p instead.\n", uri); } + ok(hr == invalid_flag_tests[i].expected, "Error: CreateUriWithFragment returned 0x%08x, expected 0x%08x. flags=0x%08x.\n", + hr, invalid_flag_tests[i].expected, invalid_flag_tests[i].flags); + ok(uri == NULL, "Error: Expected uri to be NULL, but was %p instead.\n", uri); } }
diff --git a/dlls/urlmon/uri.c b/dlls/urlmon/uri.c index 7a35f26..c18efc1 100644 --- a/dlls/urlmon/uri.c +++ b/dlls/urlmon/uri.c @@ -3952,8 +3952,56 @@ HRESULT WINAPI CreateUri(LPCWSTR pwzURI, DWORD dwFlags, DWORD_PTR dwReserved, IU HRESULT WINAPI CreateUriWithFragment(LPCWSTR pwzURI, LPCWSTR pwzFragment, DWORD dwFlags, DWORD_PTR dwReserved, IUri **ppURI) { - FIXME("(%s %s %x %x %p)\n", debugstr_w(pwzURI), debugstr_w(pwzFragment), dwFlags, (DWORD)dwReserved, ppURI); - return E_NOTIMPL; + HRESULT hres; + TRACE("(%s %s %x %x %p)\n", debugstr_w(pwzURI), debugstr_w(pwzFragment), dwFlags, (DWORD)dwReserved, ppURI); + + if(!ppURI) + return E_INVALIDARG; + + if(!pwzURI) { + *ppURI = NULL; + return E_INVALIDARG; + } + + /* Check if a fragment should be appended to the URI string. */ + if(pwzFragment) { + WCHAR *uriW; + DWORD uri_len, frag_len; + BOOL add_pound; + + /* Check if the original URI already has a fragment component. */ + if(StrChrW(pwzURI, '#')) { + *ppURI = NULL; + return E_INVALIDARG; + } + + uri_len = lstrlenW(pwzURI); + frag_len = lstrlenW(pwzFragment); + + /* If the fragment doesn't start with a '#', one will be added. */ + add_pound = *pwzFragment != '#'; + + if(add_pound) + uriW = heap_alloc((uri_len+frag_len+2)*sizeof(WCHAR)); + else + uriW = heap_alloc((uri_len+frag_len+1)*sizeof(WCHAR)); + + if(!uriW) + return E_OUTOFMEMORY; + + memcpy(uriW, pwzURI, uri_len*sizeof(WCHAR)); + if(add_pound) + uriW[uri_len++] = '#'; + memcpy(uriW+uri_len, pwzFragment, (frag_len+1)*sizeof(WCHAR)); + + hres = CreateUri(uriW, dwFlags, 0, ppURI); + + heap_free(uriW); + } else + /* A fragment string wasn't specified, so just forward the call. */ + hres = CreateUri(pwzURI, dwFlags, 0, ppURI); + + return hres; }
#define URIBUILDER_THIS(iface) DEFINE_THIS(UriBuilder, IUriBuilder, iface)