Commit 2a85bc03 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

msxml3/httprequest: Store passed data for IXMLHttpRequest::open().

parent 6e4e8fb0
......@@ -36,10 +36,22 @@ WINE_DEFAULT_DEBUG_CHANNEL(msxml);
#ifdef HAVE_LIBXML2
static const WCHAR MethodGetW[] = {'G','E','T',0};
static const WCHAR MethodPutW[] = {'P','U','T',0};
static const WCHAR MethodPostW[] = {'P','O','S','T',0};
typedef struct _httprequest
{
const struct IXMLHTTPRequestVtbl *lpVtbl;
LONG ref;
BINDVERB verb;
BSTR url;
BOOL async;
/* credentials */
BSTR user;
BSTR password;
} httprequest;
static inline httprequest *impl_from_IXMLHTTPRequest( IXMLHTTPRequest *iface )
......@@ -83,6 +95,9 @@ static ULONG WINAPI httprequest_Release(IXMLHTTPRequest *iface)
ref = InterlockedDecrement( &This->ref );
if ( ref == 0 )
{
SysFreeString(This->url);
SysFreeString(This->user);
SysFreeString(This->password);
heap_free( This );
}
......@@ -158,14 +173,57 @@ static HRESULT WINAPI httprequest_Invoke(IXMLHTTPRequest *iface, DISPID dispIdMe
return hr;
}
static HRESULT WINAPI httprequest_open(IXMLHTTPRequest *iface, BSTR bstrMethod, BSTR bstrUrl,
VARIANT varAsync, VARIANT bstrUser, VARIANT bstrPassword)
static HRESULT WINAPI httprequest_open(IXMLHTTPRequest *iface, BSTR method, BSTR url,
VARIANT async, VARIANT user, VARIANT password)
{
httprequest *This = impl_from_IXMLHTTPRequest( iface );
HRESULT hr;
VARIANT str;
FIXME("stub (%p)\n", This);
TRACE("(%p)->(%s %s)\n", This, debugstr_w(method), debugstr_w(url));
return E_NOTIMPL;
if (!method || !url) return E_INVALIDARG;
/* free previously set data */
SysFreeString(This->url);
SysFreeString(This->user);
SysFreeString(This->password);
This->url = This->user = This->password = NULL;
if (lstrcmpiW(method, MethodGetW) == 0)
{
This->verb = BINDVERB_GET;
}
else if (lstrcmpiW(method, MethodPutW) == 0)
{
This->verb = BINDVERB_PUT;
}
else if (lstrcmpiW(method, MethodPostW) == 0)
{
This->verb = BINDVERB_POST;
}
else
{
FIXME("unsupported request type %s\n", debugstr_w(method));
This->verb = -1;
return E_FAIL;
}
This->url = SysAllocString(url);
hr = VariantChangeType(&async, &async, 0, VT_BOOL);
This->async = hr == S_OK && V_BOOL(&async) == VARIANT_TRUE;
VariantInit(&str);
hr = VariantChangeType(&str, &user, 0, VT_BSTR);
if (hr == S_OK)
This->user = V_BSTR(&str);
hr = VariantChangeType(&str, &password, 0, VT_BSTR);
if (hr == S_OK)
This->password = V_BSTR(&str);
return S_OK;
}
static HRESULT WINAPI httprequest_setRequestHeader(IXMLHTTPRequest *iface, BSTR bstrHeader, BSTR bstrValue)
......@@ -324,6 +382,10 @@ HRESULT XMLHTTPRequest_create(IUnknown *pUnkOuter, LPVOID *ppObj)
req->lpVtbl = &dimimpl_vtbl;
req->ref = 1;
req->async = FALSE;
req->verb = -1;
req->url = req->user = req->password = NULL;
*ppObj = &req->lpVtbl;
TRACE("returning iface %p\n", *ppObj);
......
......@@ -2883,9 +2883,9 @@ static void test_XMLHTTP(void)
'p','o','s','t','t','e','s','t','.','p','h','p',0};
static const WCHAR wszExpectedResponse[] = {'F','A','I','L','E','D',0};
IXMLHttpRequest *pXMLHttpRequest;
BSTR bstrResponse, str1, str2;
BSTR bstrResponse, method, url;
VARIANT dummy;
VARIANT varfalse;
VARIANT async;
VARIANT varbody;
HRESULT hr = CoCreateInstance(&CLSID_XMLHTTPRequest, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLHttpRequest,
......@@ -2899,18 +2899,30 @@ static void test_XMLHTTP(void)
VariantInit(&dummy);
V_VT(&dummy) = VT_ERROR;
V_ERROR(&dummy) = DISP_E_MEMBERNOTFOUND;
VariantInit(&varfalse);
V_VT(&varfalse) = VT_BOOL;
V_BOOL(&varfalse) = VARIANT_FALSE;
VariantInit(&async);
V_VT(&async) = VT_BOOL;
V_BOOL(&async) = VARIANT_FALSE;
V_VT(&varbody) = VT_BSTR;
V_BSTR(&varbody) = SysAllocString(wszBody);
str1 = SysAllocString(wszPOST);
str2 = SysAllocString(wszUrl);
hr = IXMLHttpRequest_open(pXMLHttpRequest, str1, str2, varfalse, dummy, dummy);
todo_wine ok(hr == S_OK, "IXMLHttpRequest_open should have succeeded instead of failing with 0x%08x\n", hr);
SysFreeString(str1);
SysFreeString(str2);
method = SysAllocString(wszPOST);
url = SysAllocString(wszUrl);
/* invalid parameters */
hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, NULL, async, dummy, dummy);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IXMLHttpRequest_open(pXMLHttpRequest, method, NULL, async, dummy, dummy);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IXMLHttpRequest_open(pXMLHttpRequest, NULL, url, async, dummy, dummy);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = IXMLHttpRequest_open(pXMLHttpRequest, method, url, async, dummy, dummy);
ok(hr == S_OK, "got 0x%08x\n", hr);
SysFreeString(method);
SysFreeString(url);
hr = IXMLHttpRequest_send(pXMLHttpRequest, varbody);
if (hr == INET_E_RESOURCE_NOT_FOUND)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment