diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index 38150ecce1f..2053c96c537 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -2443,7 +2443,7 @@ static HRESULT WINAPI winhttp_request_Open( TRACE("%p, %s, %s, %s\n", request, debugstr_w(method), debugstr_w(url), debugstr_variant(&async)); - if (!method) return E_INVALIDARG; + if (!method || !url) return E_INVALIDARG; memset( &uc, 0, sizeof(uc) ); uc.dwStructSize = sizeof(uc); @@ -2667,6 +2667,7 @@ static HRESULT WINAPI winhttp_request_get_Status( TRACE("%p, %p\n", request, status); + if (!status) return E_INVALIDARG; if (request->state < REQUEST_STATE_SENT) { return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ); @@ -2692,6 +2693,7 @@ static HRESULT WINAPI winhttp_request_get_StatusText( TRACE("%p, %p\n", request, status); + if (!status) return E_INVALIDARG; if (request->state < REQUEST_STATE_SENT) { return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ); @@ -2808,6 +2810,11 @@ static HRESULT WINAPI winhttp_request_get_ResponseText( TRACE("%p, %p\n", request, body); + if (!body) return E_INVALIDARG; + if (request->state < REQUEST_STATE_SENT) + { + return HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ); + } if ((err = request_read_body( request, INFINITE ))) return HRESULT_FROM_WIN32( err ); if ((err = request_get_codepage( request, &codepage ))) return HRESULT_FROM_WIN32( err ); @@ -2830,6 +2837,7 @@ static HRESULT WINAPI winhttp_request_get_ResponseBody( TRACE("%p, %p\n", request, body); + if (!body) return E_INVALIDARG; if ((err = request_read_body( request, INFINITE ))) return HRESULT_FROM_WIN32( err ); if (!(sa = SafeArrayCreateVector( VT_UI1, 0, request->offset ))) return E_OUTOFMEMORY; diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index f70b554629e..e3f1fb6a6ba 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -2114,7 +2114,7 @@ static void test_IWinHttpRequest(void) static const WCHAR bypas_listW[] = {'b','y','p','a','s','s','l','i','s','t',0}; HRESULT hr; IWinHttpRequest *req; - BSTR method, url, username, password, response = NULL, status_text = NULL; + BSTR method, url, username, password, response = NULL, status_text = NULL, headers = NULL; VARIANT async, empty, timeout, body, proxy_server, bypass_list; VARIANT_BOOL succeeded; LONG status; @@ -2126,6 +2126,9 @@ static void test_IWinHttpRequest(void) VariantInit( &empty ); V_VT( &empty ) = VT_ERROR; + V_VT( &async ) = VT_BOOL; + V_BOOL( &async ) = VARIANT_FALSE; + hr = IWinHttpRequest_Open( req, NULL, NULL, empty ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); @@ -2133,6 +2136,9 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_Open( req, method, NULL, empty ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_Open( req, method, NULL, async ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + url = SysAllocString( url1W ); hr = IWinHttpRequest_Open( req, NULL, url, empty ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); @@ -2152,10 +2158,6 @@ static void test_IWinHttpRequest(void) hr = CoCreateInstance( &CLSID_WinHttpRequest, NULL, CLSCTX_INPROC_SERVER, &IID_IWinHttpRequest, (void **)&req ); ok( hr == S_OK, "got %08x\n", hr ); - VariantInit( &async ); - V_VT( &async ) = VT_BOOL; - V_BOOL( &async ) = VARIANT_FALSE; - SysFreeString( url ); url = SysAllocString( url2W ); hr = IWinHttpRequest_Open( req, method, url, async ); @@ -2188,12 +2190,27 @@ static void test_IWinHttpRequest(void) hr = CoCreateInstance( &CLSID_WinHttpRequest, NULL, CLSCTX_INPROC_SERVER, &IID_IWinHttpRequest, (void **)&req ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseText( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = IWinHttpRequest_get_ResponseText( req, &response ); + ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + + hr = IWinHttpRequest_get_Status( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_get_Status( req, &status ); ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + hr = IWinHttpRequest_get_StatusText( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_get_StatusText( req, &status_text ); ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseBody( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_SetTimeouts( req, 10000, 10000, 10000, 10000 ); ok( hr == S_OK, "got %08x\n", hr ); @@ -2213,6 +2230,12 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_GetAllResponseHeaders( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers ); + ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + SysFreeString( method ); method = SysAllocString( method1W ); SysFreeString( url ); @@ -2220,12 +2243,21 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_Open( req, method, url, async ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseText( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = IWinHttpRequest_get_ResponseText( req, &response ); + ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + hr = IWinHttpRequest_get_Status( req, &status ); ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); hr = IWinHttpRequest_get_StatusText( req, &status_text ); ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseBody( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_SetTimeouts( req, 10000, 10000, 10000, 10000 ); ok( hr == S_OK, "got %08x\n", hr ); @@ -2237,9 +2269,15 @@ static void test_IWinHttpRequest(void) ok( hr == E_INVALIDARG, "got %08x\n", hr ); password = SysAllocString( passwordW ); + hr = IWinHttpRequest_SetCredentials( req, NULL, password, 0xdeadbeef ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_SetCredentials( req, username, password, 0xdeadbeef ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_SetCredentials( req, NULL, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER ); ok( hr == S_OK, "got %08x\n", hr ); @@ -2256,22 +2294,41 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers ); + ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr ); + hr = IWinHttpRequest_Send( req, empty ); ok( hr == S_OK, "got %08x\n", hr ); hr = IWinHttpRequest_Send( req, empty ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseText( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = IWinHttpRequest_get_ResponseText( req, &response ); + ok( hr == S_OK, "got %08x\n", hr ); + SysFreeString( response ); + + hr = IWinHttpRequest_get_Status( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + status = 0; hr = IWinHttpRequest_get_Status( req, &status ); ok( hr == S_OK, "got %08x\n", hr ); trace("%d\n", status); + hr = IWinHttpRequest_get_StatusText( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_get_StatusText( req, &status_text ); ok( hr == S_OK, "got %08x\n", hr ); trace("%s\n", wine_dbgstr_w(status_text)); SysFreeString( status_text ); + hr = IWinHttpRequest_get_ResponseBody( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER ); ok( hr == S_OK, "got %08x\n", hr ); @@ -2281,6 +2338,13 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_GetAllResponseHeaders( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + + hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers ); + ok( hr == S_OK, "got %08x\n", hr ); + SysFreeString( headers ); + VariantInit( &timeout ); V_VT( &timeout ) = VT_I4; V_I4( &timeout ) = 10; @@ -2306,10 +2370,16 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_Send( req, empty ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseText( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + hr = IWinHttpRequest_get_ResponseText( req, &response ); ok( hr == S_OK, "got %08x\n", hr ); SysFreeString( response ); + hr = IWinHttpRequest_get_ResponseBody( req, NULL ); + ok( hr == E_INVALIDARG, "got %08x\n", hr ); + VariantInit( &body ); V_VT( &body ) = VT_ERROR; hr = IWinHttpRequest_get_ResponseBody( req, &body ); @@ -2325,6 +2395,10 @@ static void test_IWinHttpRequest(void) hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list ); ok( hr == S_OK, "got %08x\n", hr ); + hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers ); + ok( hr == S_OK, "got %08x\n", hr ); + SysFreeString( headers ); + hr = IWinHttpRequest_Send( req, empty ); ok( hr == S_OK, "got %08x\n", hr );