Nikolay Sivov : msxml3: Implement ::get_responseBody().

Alexandre Julliard julliard at winehq.org
Fri Oct 8 12:38:07 CDT 2010


Module: wine
Branch: master
Commit: f0546a1961c60b801781ccb78697f4b015eb22ad
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f0546a1961c60b801781ccb78697f4b015eb22ad

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Fri Oct  8 11:42:36 2010 +0400

msxml3: Implement ::get_responseBody().

---

 dlls/msxml3/httprequest.c  |   48 +++++++++++++++++++++++++++++++++++++++++--
 dlls/msxml3/tests/domdoc.c |   24 +++++++++++++++++++++-
 2 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/dlls/msxml3/httprequest.c b/dlls/msxml3/httprequest.c
index c09f31e..3c2c049 100644
--- a/dlls/msxml3/httprequest.c
+++ b/dlls/msxml3/httprequest.c
@@ -824,13 +824,55 @@ static HRESULT WINAPI httprequest_get_responseText(IXMLHTTPRequest *iface, BSTR
     return hr;
 }
 
-static HRESULT WINAPI httprequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *pvarBody)
+static HRESULT WINAPI httprequest_get_responseBody(IXMLHTTPRequest *iface, VARIANT *body)
 {
     httprequest *This = impl_from_IXMLHTTPRequest( iface );
+    HGLOBAL hglobal;
+    HRESULT hr;
 
-    FIXME("stub %p %p\n", This, pvarBody);
+    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)
+    {
+        void *ptr = GlobalLock(hglobal);
+        DWORD size = GlobalSize(hglobal);
+
+        SAFEARRAYBOUND bound;
+        SAFEARRAY *array;
+
+        bound.lLbound = 0;
+        bound.cElements = size;
+        array = SafeArrayCreate(VT_UI1, 1, &bound);
+
+        if (array)
+        {
+            void *dest;
+
+            V_VT(body) = VT_ARRAY | VT_UI1;
+            V_ARRAY(body) = array;
+
+            hr = SafeArrayAccessData(array, &dest);
+            if (hr == S_OK)
+            {
+                memcpy(dest, ptr, size);
+                SafeArrayUnaccessData(array);
+            }
+            else
+            {
+                VariantClear(body);
+            }
+        }
+        else
+            hr = E_FAIL;
+
+        GlobalUnlock(hglobal);
+    }
+
+    return hr;
 }
 
 static HRESULT WINAPI httprequest_get_responseStream(IXMLHTTPRequest *iface, VARIANT *pvarBody)
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index 62c59b7..d85bda9 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -3195,7 +3195,8 @@ static void test_XMLHTTP(void)
     VARIANT dummy;
     VARIANT async;
     VARIANT varbody;
-    LONG state, status, ref;
+    LONG state, status, ref, bound;
+    void *ptr;
     IDispatch *event;
     HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
                                   CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
@@ -3388,6 +3389,27 @@ todo_wine {
         SysFreeString(bstrResponse);
     }
 
+    hr = IXMLHttpRequest_get_responseBody(pXMLHttpRequest, NULL);
+    ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
+
+    V_VT(&varbody) = VT_EMPTY;
+    hr = IXMLHttpRequest_get_responseBody(pXMLHttpRequest, &varbody);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(V_VT(&varbody) == (VT_ARRAY|VT_UI1), "got type %d, expected %d\n", V_VT(&varbody), VT_ARRAY|VT_UI1);
+    ok(SafeArrayGetDim(V_ARRAY(&varbody)) == 1, "got %d, expected one dimension\n", SafeArrayGetDim(V_ARRAY(&varbody)));
+
+    bound = -1;
+    hr = SafeArrayGetLBound(V_ARRAY(&varbody), 1, &bound);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(bound == 0, "got %d, expected zero bound\n", bound);
+
+    hr = SafeArrayAccessData(V_ARRAY(&varbody), &ptr);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(memcmp(ptr, xmltestbodyA, sizeof(xmltestbodyA)-1) == 0, "got wrond body data\n");
+    SafeArrayUnaccessData(V_ARRAY(&varbody));
+
+    VariantClear(&varbody);
+
     SysFreeString(url);
 
     IDispatch_Release(event);




More information about the wine-cvs mailing list