From: Dmitry Timoshkov Subject: winhttp: Add custom implementation of IWinHttpRequest::Invoke(DISPID_HTTPREQUEST_OPTION). Take 2. Message-Id: <20150903174214.3d564365.dmitry@baikal.ru> Date: Thu, 3 Sep 2015 17:42:14 +0800 This version of the patch returns E_NOTIMPL for unsupported flags, thanks Jacek. --- dlls/winhttp/request.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ dlls/winhttp/tests/winhttp.c | 37 ------------------------------------- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index d3f4d91..4996312 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -34,6 +34,7 @@ #include "ole2.h" #include "initguid.h" #include "httprequest.h" +#include "httprequestid.h" #include "winhttp.h" #include "winhttp_private.h" @@ -2946,6 +2947,48 @@ static HRESULT WINAPI winhttp_request_Invoke( TRACE("%p, %d, %s, %d, %d, %p, %p, %p, %p\n", request, member, debugstr_guid(riid), lcid, flags, params, result, excep_info, arg_err); + if (!IsEqualIID( riid, &IID_NULL )) return DISP_E_UNKNOWNINTERFACE; + + if (member == DISPID_HTTPREQUEST_OPTION) + { + VARIANT ret_value, option; + UINT err_pos; + + if (!result) result = &ret_value; + if (!arg_err) arg_err = &err_pos; + + VariantInit( &option ); + VariantInit( result ); + + if (!flags) return S_OK; + + if (flags == DISPATCH_PROPERTYPUT) + { + hr = DispGetParam( params, 0, VT_I4, &option, arg_err ); + if (FAILED(hr)) return hr; + + hr = IWinHttpRequest_put_Option( &request->IWinHttpRequest_iface, V_I4( &option ), params->rgvarg[0] ); + if (FAILED(hr)) + WARN("put_Option(%d) failed: %x\n", V_I4( &option ), hr); + return hr; + } + else if (flags & (DISPATCH_PROPERTYGET | DISPATCH_METHOD)) + { + hr = DispGetParam( params, 0, VT_I4, &option, arg_err ); + if (FAILED(hr)) return hr; + + hr = IWinHttpRequest_get_Option( &request->IWinHttpRequest_iface, V_I4( &option ), result ); + if (FAILED(hr)) + WARN("get_Option(%d) failed: %x\n", V_I4( &option ), hr); + return hr; + } + + FIXME("unsupported flags %x\n", flags); + return E_NOTIMPL; + } + + /* fallback to standard implementation */ + hr = get_typeinfo( IWinHttpRequest_tid, &typeinfo ); if (SUCCEEDED(hr)) { @@ -4216,6 +4259,7 @@ HRESULT WinHttpRequest_create( void **obj ) request->state = REQUEST_STATE_UNINITIALIZED; request->proxy.lpszProxy = NULL; request->proxy.lpszProxyBypass = NULL; + request->url_codepage = CP_UTF8; InitializeCriticalSection( &request->cs ); request->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": winhttp_request.cs"); diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index 05993f0..d6678da 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -3560,7 +3560,6 @@ static void request_get_property(IWinHttpRequest *request, int property, VARIANT VariantInit(ret); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, ret, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); } @@ -3605,9 +3604,7 @@ static void test_IWinHttpRequest_Invoke(void) ok(id == DISPID_HTTPREQUEST_OPTION, "expected DISPID_HTTPREQUEST_OPTION, got %u\n", id); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == CP_UTF8, "expected CP_UTF8, got %d\n", V_I4(&ret)); memset(¶ms, 0, sizeof(params)); @@ -3621,13 +3618,10 @@ todo_wine VariantInit(&ret); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_METHOD, ¶ms, NULL, NULL, &err); -todo_wine ok(hr == S_OK, "error %#x\n", hr); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == CP_UTF8, "expected CP_UTF8, got %d\n", V_I4(&ret)); memset(¶ms, 0, sizeof(params)); @@ -3641,13 +3635,10 @@ todo_wine VariantInit(&ret); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_METHOD | DISPATCH_PROPERTYPUT, ¶ms, NULL, NULL, &err); -todo_wine ok(hr == S_OK, "error %#x\n", hr); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == CP_UTF8, "expected CP_UTF8, got %d\n", V_I4(&ret)); memset(¶ms, 0, sizeof(params)); @@ -3661,13 +3652,10 @@ todo_wine VariantInit(&ret); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_PROPERTYPUT, ¶ms, NULL, NULL, &err); -todo_wine ok(hr == S_OK, "error %#x\n", hr); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == 1252, "expected 1252, got %d\n", V_I4(&ret)); memset(¶ms, 0, sizeof(params)); @@ -3680,39 +3668,29 @@ todo_wine V_VT(&arg[1]) = VT_R8; V_R8(&arg[1]) = 2.0; /* WinHttpRequestOption_URLCodePage */ hr = IWinHttpRequest_Invoke(request, id, &IID_NULL, 0, DISPATCH_METHOD, ¶ms, NULL, NULL, &err); -todo_wine ok(hr == S_OK, "error %#x\n", hr); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == 1252, "expected 1252, got %d\n", V_I4(&ret)); VariantInit(&ret); hr = IWinHttpRequest_Invoke(request, id, &IID_NULL, 0, DISPATCH_METHOD, ¶ms, &ret, NULL, &err); -todo_wine ok(hr == S_OK, "error %#x\n", hr); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == 1252, "expected 1252, got %d\n", V_I4(&ret)); VariantInit(&ret); hr = IWinHttpRequest_Invoke(request, id, &IID_NULL, 0, DISPATCH_PROPERTYPUT, ¶ms, &ret, NULL, &err); -todo_wine ok(hr == S_OK, "error %#x\n", hr); request_get_property(request, WinHttpRequestOption_URLCodePage, &ret); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == CP_UTF8, "expected CP_UTF8, got %d\n", V_I4(&ret)); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_PROPERTYPUT, ¶ms, NULL, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); hr = IWinHttpRequest_Invoke(request, 255, &IID_NULL, 0, DISPATCH_PROPERTYPUT, ¶ms, NULL, NULL, NULL); @@ -3720,7 +3698,6 @@ todo_wine VariantInit(&ret); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_IUnknown, 0, DISPATCH_PROPERTYPUT, ¶ms, &ret, NULL, &err); -todo_wine ok(hr == DISP_E_UNKNOWNINTERFACE, "error %#x\n", hr); VariantInit(&ret); @@ -3729,7 +3706,6 @@ if (0) /* crashes */ params.cArgs = 1; hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_PROPERTYPUT, ¶ms, &ret, NULL, &err); -todo_wine ok(hr == DISP_E_TYPEMISMATCH, "error %#x\n", hr); VariantInit(&arg[2]); @@ -3746,48 +3722,36 @@ todo_wine V_VT(&arg[0]) = VT_I4; V_I4(&arg[0]) = WinHttpRequestOption_URLCodePage; hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, NULL, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); V_VT(&ret) = 0xdead; V_I4(&ret) = 0xbeef; hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_METHOD|DISPATCH_PROPERTYGET, ¶ms, &ret, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == CP_UTF8, "expected CP_UTF8, got %d\n", V_I4(&ret)); V_VT(&ret) = 0xdead; V_I4(&ret) = 0xbeef; hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_METHOD, ¶ms, &ret, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); -todo_wine ok(V_VT(&ret) == VT_I4, "expected VT_I4, got %d\n", V_VT(&ret)); -todo_wine ok(V_I4(&ret) == CP_UTF8, "expected CP_UTF8, got %d\n", V_I4(&ret)); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_METHOD|DISPATCH_PROPERTYGET, ¶ms, NULL, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); V_VT(&ret) = 0xdead; V_I4(&ret) = 0xbeef; hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, 0, ¶ms, &ret, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); -todo_wine ok(V_VT(&ret) == VT_EMPTY, "expected VT_EMPTY, got %d\n", V_VT(&ret)); ok(V_I4(&ret) == 0xbeef || V_I4(&ret) == 0 /* Win8 */, "expected 0xdead, got %d\n", V_I4(&ret)); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, 0, ¶ms, NULL, NULL, NULL); -todo_wine ok(hr == S_OK, "error %#x\n", hr); hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_IUnknown, 0, DISPATCH_PROPERTYGET, ¶ms, NULL, NULL, NULL); -todo_wine ok(hr == DISP_E_UNKNOWNINTERFACE, "error %#x\n", hr); params.cArgs = 2; @@ -3797,7 +3761,6 @@ todo_wine params.cArgs = 0; hr = IWinHttpRequest_Invoke(request, DISPID_HTTPREQUEST_OPTION, &IID_NULL, 0, DISPATCH_PROPERTYGET, ¶ms, NULL, NULL, NULL); -todo_wine ok(hr == DISP_E_PARAMNOTFOUND, "error %#x\n", hr); SysFreeString(utf8); -- 2.4.8