Commit 1def0982 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Always clear last error on success.

parent 09de5cdb
......@@ -541,6 +541,7 @@ BOOL WINAPI WinHttpAddRequestHeaders( HINTERNET hrequest, LPCWSTR headers, DWORD
ret = add_request_headers( request, headers, len, flags );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -848,6 +849,7 @@ BOOL WINAPI WinHttpQueryHeaders( HINTERNET hrequest, DWORD level, LPCWSTR name,
ret = query_headers( request, level, name, buffer, buflen, index );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1265,6 +1267,7 @@ BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, LPCWSTR headers, DWORD heade
ret = send_request( request, headers, headers_len, optional, optional_len, total_len, context, FALSE );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1388,6 +1391,7 @@ BOOL WINAPI WinHttpQueryAuthSchemes( HINTERNET hrequest, LPDWORD supported, LPDW
}
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1842,6 +1846,7 @@ BOOL WINAPI WinHttpSetCredentials( HINTERNET hrequest, DWORD target, DWORD schem
ret = set_credentials( request, target, scheme, username, password );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -2484,6 +2489,7 @@ BOOL WINAPI WinHttpReceiveResponse( HINTERNET hrequest, LPVOID reserved )
ret = receive_response( request, FALSE );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -2555,6 +2561,7 @@ BOOL WINAPI WinHttpQueryDataAvailable( HINTERNET hrequest, LPDWORD available )
ret = query_data_available( request, available, FALSE );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -2604,6 +2611,7 @@ BOOL WINAPI WinHttpReadData( HINTERNET hrequest, LPVOID buffer, DWORD to_read, L
ret = read_data( request, buffer, to_read, read, FALSE );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -2675,6 +2683,7 @@ BOOL WINAPI WinHttpWriteData( HINTERNET hrequest, LPCVOID buffer, DWORD to_write
ret = write_data( request, buffer, to_write, written, FALSE );
release_object( &request->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......
......@@ -276,6 +276,7 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST
end:
release_object( &session->hdr );
TRACE("returning %p\n", handle);
if (handle) set_last_error( ERROR_SUCCESS );
return handle;
}
......@@ -552,6 +553,7 @@ end:
release_object( &connect->hdr );
release_object( &session->hdr );
TRACE("returning %p\n", hconnect);
if (hconnect) set_last_error( ERROR_SUCCESS );
return hconnect;
}
......@@ -1127,6 +1129,7 @@ end:
release_object( &request->hdr );
release_object( &connect->hdr );
TRACE("returning %p\n", hrequest);
if (hrequest) set_last_error( ERROR_SUCCESS );
return hrequest;
}
......@@ -1146,6 +1149,7 @@ BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
}
release_object( hdr );
free_handle( handle );
set_last_error( ERROR_SUCCESS );
return TRUE;
}
......@@ -1206,6 +1210,7 @@ BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, L
ret = query_option( hdr, option, buffer, buflen );
release_object( hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1264,6 +1269,7 @@ BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWO
ret = set_option( hdr, option, buffer, buflen );
release_object( hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1373,6 +1379,7 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
if (!(urlW = strdupAW( system_url ))) return FALSE;
*url = urlW;
set_last_error( ERROR_SUCCESS );
return TRUE;
}
if (flags & WINHTTP_AUTO_DETECT_TYPE_DHCP)
......@@ -1433,6 +1440,7 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url )
set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED );
*url = NULL;
}
else set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1600,6 +1608,7 @@ BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
info->lpszProxy = NULL;
info->lpszProxyBypass = NULL;
}
set_last_error( ERROR_SUCCESS );
return TRUE;
}
......@@ -1682,6 +1691,7 @@ done:
GlobalFree( config->lpszProxyBypass );
config->lpszProxyBypass = NULL;
}
else set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1866,6 +1876,7 @@ BOOL WINAPI WinHttpGetProxyForUrl( HINTERNET hsession, LPCWSTR url, WINHTTP_AUTO
done:
GlobalFree( detected_pac_url );
release_object( &session->hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1973,6 +1984,7 @@ BOOL WINAPI WinHttpSetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info )
}
RegCloseKey( key );
}
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -1997,6 +2009,7 @@ WINHTTP_STATUS_CALLBACK WINAPI WinHttpSetStatusCallback( HINTERNET handle, WINHT
hdr->notify_mask = flags;
release_object( hdr );
set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -2065,6 +2078,7 @@ BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int
ret = FALSE;
}
release_object( hdr );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -2087,7 +2101,11 @@ BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
TRACE("%p, %p\n", time, string);
if (!time || !string) return FALSE;
if (!time || !string)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
}
sprintfW( string, format,
wkday[time->wDayOfWeek],
......@@ -2098,6 +2116,7 @@ BOOL WINAPI WinHttpTimeFromSystemTime( const SYSTEMTIME *time, LPWSTR string )
time->wMinute,
time->wSecond );
set_last_error( ERROR_SUCCESS );
return TRUE;
}
......@@ -2112,7 +2131,11 @@ BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
TRACE("%s, %p\n", debugstr_w(string), time);
if (!string || !time) return FALSE;
if (!string || !time)
{
set_last_error( ERROR_INVALID_PARAMETER );
return FALSE;
}
/* Windows does this too */
GetSystemTime( time );
......@@ -2121,6 +2144,8 @@ BOOL WINAPI WinHttpTimeToSystemTime( LPCWSTR string, SYSTEMTIME *time )
* a SYSTEMTIME structure.
*/
set_last_error( ERROR_SUCCESS );
while (*s && !isalphaW( *s )) s++;
if (s[0] == '\0' || s[1] == '\0' || s[2] == '\0') return TRUE;
time->wDayOfWeek = 7;
......
......@@ -474,7 +474,7 @@ static const struct notification async_test[] =
static void test_async( void )
{
HANDLE ses, con, req, event;
DWORD size, status;
DWORD size, status, err;
BOOL ret, unload = TRUE;
struct info info, *context = &info;
char buffer[1024];
......@@ -495,22 +495,36 @@ static void test_async( void )
unload = FALSE;
}
SetLastError( 0xdeadbeef );
WinHttpSetStatusCallback( ses, check_notification, WINHTTP_CALLBACK_FLAG_ALL_NOTIFICATIONS, 0 );
err = GetLastError();
ok(err == ERROR_SUCCESS || broken(err == 0xdeadbeef) /* < win7 */, "got %u\n", err);
SetLastError( 0xdeadbeef );
ret = WinHttpSetOption( ses, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(struct info *) );
ok(ret, "failed to set context value %u\n", GetLastError());
err = GetLastError();
ok(ret, "failed to set context value %u\n", err);
ok(err == ERROR_SUCCESS || broken(err == 0xdeadbeef) /* < win7 */, "got %u\n", err);
setup_test( &info, winhttp_connect, __LINE__ );
SetLastError( 0xdeadbeef );
con = WinHttpConnect( ses, test_winehq, 0, 0 );
ok(con != NULL, "failed to open a connection %u\n", GetLastError());
err = GetLastError();
ok(con != NULL, "failed to open a connection %u\n", err);
ok(err == ERROR_SUCCESS || broken(err == WSAEINVAL) /* < win7 */, "got %u\n", err);
setup_test( &info, winhttp_open_request, __LINE__ );
SetLastError( 0xdeadbeef );
req = WinHttpOpenRequest( con, NULL, NULL, NULL, NULL, NULL, 0 );
ok(req != NULL, "failed to open a request %u\n", GetLastError());
err = GetLastError();
ok(req != NULL, "failed to open a request %u\n", err);
ok(err == ERROR_SUCCESS, "got %u\n", err);
setup_test( &info, winhttp_send_request, __LINE__ );
SetLastError( 0xdeadbeef );
ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 );
if (!ret && GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT)
err = GetLastError();
if (!ret && err == ERROR_WINHTTP_CANNOT_CONNECT)
{
skip("connection failed, skipping\n");
WinHttpCloseHandle( req );
......@@ -519,30 +533,43 @@ static void test_async( void )
CloseHandle( info.wait );
return;
}
ok(ret, "failed to send request %u\n", GetLastError());
ok(ret, "failed to send request %u\n", err);
ok(err == ERROR_SUCCESS, "got %u\n", err);
WaitForSingleObject( info.wait, INFINITE );
setup_test( &info, winhttp_receive_response, __LINE__ );
SetLastError( 0xdeadbeef );
ret = WinHttpReceiveResponse( req, NULL );
ok(ret, "failed to receive response %u\n", GetLastError());
err = GetLastError();
ok(ret, "failed to receive response %u\n", err);
ok(err == ERROR_SUCCESS, "got %u\n", err);
WaitForSingleObject( info.wait, INFINITE );
size = sizeof(status);
SetLastError( 0xdeadbeef );
ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL );
ok(ret, "failed unexpectedly %u\n", GetLastError());
err = GetLastError();
ok(ret, "failed unexpectedly %u\n", err);
ok(status == 200, "request failed unexpectedly %u\n", status);
ok(err == ERROR_SUCCESS || broken(err == 0xdeadbeef) /* < win7 */, "got %u\n", err);
setup_test( &info, winhttp_query_data, __LINE__ );
SetLastError( 0xdeadbeef );
ret = WinHttpQueryDataAvailable( req, NULL );
ok(ret, "failed to query data available %u\n", GetLastError());
err = GetLastError();
ok(ret, "failed to query data available %u\n", err);
ok(err == ERROR_SUCCESS || err == ERROR_IO_PENDING || broken(err == 0xdeadbeef) /* < win7 */, "got %u\n", err);
WaitForSingleObject( info.wait, INFINITE );
setup_test( &info, winhttp_read_data, __LINE__ );
SetLastError( 0xdeadbeef );
ret = WinHttpReadData( req, buffer, sizeof(buffer), NULL );
ok(ret, "failed to query data available %u\n", GetLastError());
err = GetLastError();
ok(ret, "failed to read data %u\n", err);
ok(err == ERROR_SUCCESS, "got %u\n", err);
WaitForSingleObject( info.wait, INFINITE );
......
......@@ -169,11 +169,14 @@ static void WinHttpCreateUrl_test( void )
ok( len == 57, "expected len 57 got %u\n", len );
/* allocated url, NULL scheme */
SetLastError( 0xdeadbeef );
uc.lpszScheme = NULL;
url[0] = 0;
len = 256;
ret = WinHttpCreateUrl( &uc, 0, url, &len );
ok( ret, "expected success\n" );
ok( GetLastError() == ERROR_SUCCESS || broken(GetLastError() == 0xdeadbeef) /* < win7 */,
"expected ERROR_SUCCESS got %u\n", GetLastError() );
ok( len == 56, "expected len 56 got %u\n", len );
ok( !lstrcmpW( url, url1 ), "url doesn't match\n" );
......@@ -380,9 +383,13 @@ static void WinHttpCrackUrl_test( void )
/* no buffers */
reset_url_components( &uc );
SetLastError( 0xdeadbeef );
ret = WinHttpCrackUrl( url_k1, 0, 0,&uc);
error = GetLastError();
ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() );
ok( ret, "WinHttpCrackUrl failed le=%u\n", error );
ok( error == ERROR_SUCCESS || broken(error == ERROR_INVALID_PARAMETER) /* < win7 */,
"got %u, expected ERROR_SUCCESS\n", error );
ok( uc.nScheme == INTERNET_SCHEME_HTTP, "unexpected scheme\n" );
ok( uc.lpszScheme == url_k1,"unexpected scheme\n" );
ok( uc.dwSchemeLength == 4, "unexpected scheme length\n" );
......
......@@ -304,6 +304,7 @@ exit:
if (ret) uc->nScheme = scheme;
heap_free( url_decoded );
heap_free( url_escaped );
if (ret) set_last_error( ERROR_SUCCESS );
return ret;
}
......@@ -522,5 +523,6 @@ BOOL WINAPI WinHttpCreateUrl( LPURL_COMPONENTS uc, DWORD flags, LPWSTR url, LPDW
}
}
*url = 0;
set_last_error( ERROR_SUCCESS );
return TRUE;
}
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