msxml3: Implement ::get_responseText() for UTF-8 and UTF-16 (little endian) response encoding.
This commit is contained in:
parent
62656c57bf
commit
eebf331e89
|
@ -40,6 +40,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
||||||
|
|
||||||
#ifdef HAVE_LIBXML2
|
#ifdef HAVE_LIBXML2
|
||||||
|
|
||||||
|
#include <libxml/encoding.h>
|
||||||
|
|
||||||
static const WCHAR MethodGetW[] = {'G','E','T',0};
|
static const WCHAR MethodGetW[] = {'G','E','T',0};
|
||||||
static const WCHAR MethodPutW[] = {'P','U','T',0};
|
static const WCHAR MethodPutW[] = {'P','U','T',0};
|
||||||
static const WCHAR MethodPostW[] = {'P','O','S','T',0};
|
static const WCHAR MethodPostW[] = {'P','O','S','T',0};
|
||||||
|
@ -770,13 +772,53 @@ static HRESULT WINAPI httprequest_get_responseXML(IXMLHTTPRequest *iface, IDispa
|
||||||
return E_NOTIMPL;
|
return E_NOTIMPL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI httprequest_get_responseText(IXMLHTTPRequest *iface, BSTR *pbstrBody)
|
static HRESULT WINAPI httprequest_get_responseText(IXMLHTTPRequest *iface, BSTR *body)
|
||||||
{
|
{
|
||||||
httprequest *This = impl_from_IXMLHTTPRequest( iface );
|
httprequest *This = impl_from_IXMLHTTPRequest( iface );
|
||||||
|
HGLOBAL hglobal;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
FIXME("stub %p %p\n", This, pbstrBody);
|
TRACE("(%p)->(%p)\n", This, body);
|
||||||
|
|
||||||
return E_NOTIMPL;
|
if (!body) return E_INVALIDARG;
|
||||||
|
if (This->state != READYSTATE_COMPLETE) return E_FAIL;
|
||||||
|
|
||||||
|
hr = GetHGlobalFromStream(This->bsc->stream, &hglobal);
|
||||||
|
if (hr == S_OK)
|
||||||
|
{
|
||||||
|
xmlChar *ptr = GlobalLock(hglobal);
|
||||||
|
DWORD size = GlobalSize(hglobal);
|
||||||
|
xmlCharEncoding encoding = XML_CHAR_ENCODING_UTF8;
|
||||||
|
|
||||||
|
/* try to determine data encoding */
|
||||||
|
if (size >= 4)
|
||||||
|
{
|
||||||
|
encoding = xmlDetectCharEncoding(ptr, 4);
|
||||||
|
TRACE("detected encoding: %s\n", xmlGetCharEncodingName(encoding));
|
||||||
|
if ( encoding != XML_CHAR_ENCODING_UTF8 &&
|
||||||
|
encoding != XML_CHAR_ENCODING_UTF16LE &&
|
||||||
|
encoding != XML_CHAR_ENCODING_NONE )
|
||||||
|
{
|
||||||
|
FIXME("unsupported encoding: %s\n", xmlGetCharEncodingName(encoding));
|
||||||
|
GlobalUnlock(hglobal);
|
||||||
|
return E_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* without BOM assume UTF-8 */
|
||||||
|
if (encoding == XML_CHAR_ENCODING_UTF8 ||
|
||||||
|
encoding == XML_CHAR_ENCODING_NONE )
|
||||||
|
{
|
||||||
|
*body = bstr_from_xmlChar(ptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*body = SysAllocStringByteLen((LPCSTR)ptr, size);
|
||||||
|
|
||||||
|
if (!*body) hr = E_OUTOFMEMORY;
|
||||||
|
GlobalUnlock(hglobal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI httprequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *pvarBody)
|
static HRESULT WINAPI httprequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *pvarBody)
|
||||||
|
|
|
@ -3188,6 +3188,8 @@ static void test_XMLHTTP(void)
|
||||||
'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
|
'c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m','/',
|
||||||
'x','m','l','t','e','s','t','.','x','m','l',0};
|
'x','m','l','t','e','s','t','.','x','m','l',0};
|
||||||
static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
|
static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
|
||||||
|
static const CHAR xmltestbodyA[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>\n";
|
||||||
|
|
||||||
IXMLHttpRequest *pXMLHttpRequest;
|
IXMLHttpRequest *pXMLHttpRequest;
|
||||||
BSTR bstrResponse, method, url;
|
BSTR bstrResponse, method, url;
|
||||||
VARIANT dummy;
|
VARIANT dummy;
|
||||||
|
@ -3359,6 +3361,18 @@ todo_wine {
|
||||||
}
|
}
|
||||||
ok(hr == S_OK, "got 0x%08x\n", hr);
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, NULL);
|
||||||
|
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
|
||||||
|
|
||||||
|
hr = IXMLHttpRequest_get_responseText(pXMLHttpRequest, &bstrResponse);
|
||||||
|
ok(hr == S_OK, "got 0x%08x\n", hr);
|
||||||
|
if(hr == S_OK)
|
||||||
|
{
|
||||||
|
ok(!memcmp(bstrResponse, _bstr_(xmltestbodyA), sizeof(xmltestbodyA)*sizeof(WCHAR)),
|
||||||
|
"expected %s, got %s\n", xmltestbodyA, wine_dbgstr_w(bstrResponse));
|
||||||
|
SysFreeString(bstrResponse);
|
||||||
|
}
|
||||||
|
|
||||||
SysFreeString(url);
|
SysFreeString(url);
|
||||||
|
|
||||||
IDispatch_Release(event);
|
IDispatch_Release(event);
|
||||||
|
|
Loading…
Reference in New Issue