msxml3: Use IUri API to load documents.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2018-01-23 11:27:54 +03:00 committed by Alexandre Julliard
parent de90cca586
commit cdaf5625d1
4 changed files with 118 additions and 75 deletions

View File

@ -242,7 +242,7 @@ static const struct IBindStatusCallbackVtbl bsc_vtbl =
bsc_OnObjectAvailable bsc_OnObjectAvailable
}; };
HRESULT create_moniker_from_url(LPCWSTR url, IMoniker **mon) HRESULT create_uri(const WCHAR *url, IUri **uri)
{ {
WCHAR fileUrl[INTERNET_MAX_URL_LENGTH]; WCHAR fileUrl[INTERNET_MAX_URL_LENGTH];
@ -267,7 +267,22 @@ HRESULT create_moniker_from_url(LPCWSTR url, IMoniker **mon)
url = fileUrl; url = fileUrl;
} }
return CreateURLMonikerEx(NULL, url, mon, 0); return CreateUri(url, Uri_CREATE_ALLOW_RELATIVE | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, uri);
}
HRESULT create_moniker_from_url(LPCWSTR url, IMoniker **mon)
{
HRESULT hr;
IUri *uri;
TRACE("%s\n", debugstr_w(url));
if (FAILED(hr = create_uri(url, &uri)))
return hr;
hr = CreateURLMonikerEx2(NULL, uri, mon, 0);
IUri_Release(uri);
return hr;
} }
HRESULT bind_url(IMoniker *mon, HRESULT (*onDataAvailable)(void*,char*,DWORD), HRESULT bind_url(IMoniker *mon, HRESULT (*onDataAvailable)(void*,char*,DWORD),

View File

@ -86,7 +86,7 @@ typedef struct {
xmlChar const* selectNsStr; xmlChar const* selectNsStr;
LONG selectNsStr_len; LONG selectNsStr_len;
BOOL XPath; BOOL XPath;
WCHAR *url; IUri *uri;
} domdoc_properties; } domdoc_properties;
typedef struct ConnectionPoint ConnectionPoint; typedef struct ConnectionPoint ConnectionPoint;
@ -298,8 +298,8 @@ static domdoc_properties *create_properties(MSXML_VERSION version)
properties->version = version; properties->version = version;
properties->XPath = (version == MSXML4 || version == MSXML6); properties->XPath = (version == MSXML4 || version == MSXML6);
/* document url */ /* document uri */
properties->url = NULL; properties->uri = NULL;
return properties; return properties;
} }
@ -335,16 +335,9 @@ static domdoc_properties* copy_properties(domdoc_properties const* properties)
list_add_tail(&pcopy->selectNsList, &new_ns->entry); list_add_tail(&pcopy->selectNsList, &new_ns->entry);
} }
if (properties->url) pcopy->uri = properties->uri;
{ if (pcopy->uri)
int len = strlenW(properties->url); IUri_AddRef(pcopy->uri);
pcopy->url = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
memcpy(pcopy->url, properties->url, len*sizeof(WCHAR));
pcopy->url[len] = 0;
}
else
pcopy->url = NULL;
} }
return pcopy; return pcopy;
@ -358,7 +351,8 @@ static void free_properties(domdoc_properties* properties)
IXMLDOMSchemaCollection2_Release(properties->schemaCache); IXMLDOMSchemaCollection2_Release(properties->schemaCache);
clear_selectNsList(&properties->selectNsList); clear_selectNsList(&properties->selectNsList);
heap_free((xmlChar*)properties->selectNsStr); heap_free((xmlChar*)properties->selectNsStr);
CoTaskMemFree(properties->url); if (properties->uri)
IUri_Release(properties->uri);
heap_free(properties); heap_free(properties);
} }
} }
@ -2293,16 +2287,20 @@ static HRESULT WINAPI domdoc_load(
if ( filename ) if ( filename )
{ {
IMoniker *mon; IMoniker *mon;
IUri *uri;
CoTaskMemFree(This->properties->url); if (This->properties->uri)
This->properties->url = NULL; {
IUri_Release(This->properties->uri);
This->properties->uri = NULL;
}
hr = create_moniker_from_url( filename, &mon); hr = create_uri(filename, &uri);
if (SUCCEEDED(hr))
hr = CreateURLMonikerEx2(NULL, uri, &mon, 0);
if ( SUCCEEDED(hr) ) if ( SUCCEEDED(hr) )
{ {
hr = domdoc_load_moniker( This, mon ); hr = domdoc_load_moniker( This, mon );
if (hr == S_OK)
IMoniker_GetDisplayName(mon, NULL, NULL, &This->properties->url);
IMoniker_Release(mon); IMoniker_Release(mon);
} }
@ -2310,6 +2308,7 @@ static HRESULT WINAPI domdoc_load(
This->error = E_FAIL; This->error = E_FAIL;
else else
{ {
This->properties->uri = uri;
hr = This->error = S_OK; hr = This->error = S_OK;
*isSuccessful = VARIANT_TRUE; *isSuccessful = VARIANT_TRUE;
} }
@ -2374,16 +2373,10 @@ static HRESULT WINAPI domdoc_get_url(
if (!url) if (!url)
return E_INVALIDARG; return E_INVALIDARG;
if (This->properties->url) if (!This->properties->uri)
{
*url = SysAllocString(This->properties->url);
if (!*url)
return E_OUTOFMEMORY;
return S_OK;
}
else
return return_null_bstr(url); return return_null_bstr(url);
return IUri_GetPropertyBSTR(This->properties->uri, Uri_PROPERTY_DISPLAY_URI, url, 0);
} }

View File

@ -544,6 +544,7 @@ static inline const CLSID* SchemaCache_version(MSXML_VERSION v)
typedef struct bsc_t bsc_t; typedef struct bsc_t bsc_t;
HRESULT create_moniker_from_url(LPCWSTR, IMoniker**) DECLSPEC_HIDDEN; HRESULT create_moniker_from_url(LPCWSTR, IMoniker**) DECLSPEC_HIDDEN;
HRESULT create_uri(const WCHAR *, IUri **) DECLSPEC_HIDDEN;
HRESULT bind_url(IMoniker*, HRESULT (*onDataAvailable)(void*,char*,DWORD), void*, bsc_t**) DECLSPEC_HIDDEN; HRESULT bind_url(IMoniker*, HRESULT (*onDataAvailable)(void*,char*,DWORD), void*, bsc_t**) DECLSPEC_HIDDEN;
HRESULT detach_bsc(bsc_t*) DECLSPEC_HIDDEN; HRESULT detach_bsc(bsc_t*) DECLSPEC_HIDDEN;

View File

@ -10152,13 +10152,68 @@ static void write_to_file(const char *name, const char *data)
CloseHandle(hfile); CloseHandle(hfile);
} }
static void test_doc_load_from_path(IXMLDOMDocument *doc, const char *path)
{
IXMLDOMDocument *doc2;
IXMLDOMElement *elem;
BSTR url, url2;
VARIANT_BOOL b;
VARIANT src;
HRESULT hr;
url = _bstr_(path);
V_VT(&src) = VT_BSTR;
V_BSTR(&src) = url;
hr = IXMLDOMDocument_load(doc, src, &b);
ok(hr == S_OK, "Failed to load document, %#x.\n", hr);
ok(b == VARIANT_TRUE, "got %d\n", b);
V_VT(&src) = VT_BSTR | VT_BYREF;
V_BSTRREF(&src) = &url;
hr = IXMLDOMDocument_load(doc, src, &b);
ok(hr == S_OK, "Failed to load document, %#x.\n", hr);
ok(b == VARIANT_TRUE, "got %d\n", b);
url = NULL;
hr = IXMLDOMDocument_get_url(doc, &url);
ok(hr == S_OK, "Failed to get document url, hr %#x.\n", hr);
hr = IXMLDOMDocument_get_documentElement(doc, &elem);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* Create another instance for the same document, check url */
hr = IXMLDOMElement_get_ownerDocument(elem, &doc2);
ok(hr == S_OK, "Failed to get owner document, hr %#x.\n", hr);
hr = IXMLDOMDocument_get_url(doc2, &url2);
ok(hr == S_OK, "Failed to get document url, hr %#x.\n", hr);
ok(!lstrcmpW(url, url2), "Unexpected url %s.\n", wine_dbgstr_w(url2));
IXMLDOMDocument_Release(doc2);
IXMLDOMElement_Release(elem);
SysFreeString(url2);
SysFreeString(url);
}
static void url_forward_slash(char *url)
{
char *p = url;
while (*p)
{
if (*p == '\\')
*p = '/';
p++;
}
}
static void test_load(void) static void test_load(void)
{ {
IXMLDOMDocument *doc, *doc2; char path[MAX_PATH], path2[MAX_PATH];
BSTR pathW, bstr1, bstr2;
IXMLDOMNodeList *list; IXMLDOMNodeList *list;
IXMLDOMElement *elem; IXMLDOMDocument *doc;
char path[MAX_PATH]; BSTR bstr1, bstr2;
VARIANT_BOOL b; VARIANT_BOOL b;
VARIANT src; VARIANT src;
HRESULT hr; HRESULT hr;
@ -10179,47 +10234,26 @@ static void test_load(void)
EXPECT_HR(hr, E_INVALIDARG); EXPECT_HR(hr, E_INVALIDARG);
ok(b == VARIANT_FALSE, "got %d\n", b); ok(b == VARIANT_FALSE, "got %d\n", b);
pathW = _bstr_(path); /* "file://" url */
strcpy(path2, "file://");
strcat(path2, path);
test_doc_load_from_path(doc, path2);
/* load from path: VT_BSTR */ /* file:// url, forward slashes */
V_VT(&src) = VT_BSTR; url_forward_slash(path2);
V_BSTR(&src) = pathW; test_doc_load_from_path(doc, path2);
hr = IXMLDOMDocument_load(doc, src, &b);
EXPECT_HR(hr, S_OK);
ok(b == VARIANT_TRUE, "got %d\n", b);
bstr1 = NULL; /* "file:/" url */
hr = IXMLDOMDocument_get_url(doc, &bstr1); strcpy(path2, "file:/");
ok(hr == S_OK, "got 0x%08x\n", hr); strcat(path2, path);
SysFreeString(bstr1); test_doc_load_from_path(doc, path);
/* load from a path: VT_BSTR|VT_BYREF */ /* file:/ with forward slashes. */
V_VT(&src) = VT_BSTR | VT_BYREF; url_forward_slash(path2);
V_BSTRREF(&src) = &pathW; test_doc_load_from_path(doc, path2);
hr = IXMLDOMDocument_load(doc, src, &b);
EXPECT_HR(hr, S_OK);
ok(b == VARIANT_TRUE, "got %d\n", b);
bstr1 = NULL; /* Regular local path. */
hr = IXMLDOMDocument_get_url(doc, &bstr1); test_doc_load_from_path(doc, path);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXMLDOMDocument_get_documentElement(doc, &elem);
ok(hr == S_OK, "got 0x%08x\n", hr);
/* create another instance for the same document, check url */
hr = IXMLDOMElement_get_ownerDocument(elem, &doc2);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IXMLDOMDocument_get_url(doc, &bstr2);
ok(hr == S_OK, "got 0x%08x\n", hr);
ok(!lstrcmpW(bstr1, bstr2), "got %s\n", wine_dbgstr_w(bstr2));
IXMLDOMDocument_Release(doc2);
IXMLDOMElement_Release(elem);
SysFreeString(bstr1);
SysFreeString(bstr2);
/* load from a path: VT_BSTR|VT_BYREF, null ptr */ /* load from a path: VT_BSTR|VT_BYREF, null ptr */
V_VT(&src) = VT_BSTR | VT_BYREF; V_VT(&src) = VT_BSTR | VT_BYREF;
@ -10239,7 +10273,7 @@ static void test_load(void)
write_to_file(path, nocontent); write_to_file(path, nocontent);
V_VT(&src) = VT_BSTR; V_VT(&src) = VT_BSTR;
V_BSTR(&src) = pathW; V_BSTR(&src) = _bstr_(path);
b = VARIANT_TRUE; b = VARIANT_TRUE;
hr = IXMLDOMDocument_load(doc, src, &b); hr = IXMLDOMDocument_load(doc, src, &b);
ok(hr == S_FALSE, "got 0x%08x\n", hr); ok(hr == S_FALSE, "got 0x%08x\n", hr);