Commit b73e31c6 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Return error directly from HTTP_Connect.

parent e1958a67
...@@ -3880,7 +3880,7 @@ BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest, ...@@ -3880,7 +3880,7 @@ BOOL WINAPI HttpSendRequestExA(HINTERNET hRequest,
header = HeapAlloc(GetProcessHeap(),0,headerlen*sizeof(WCHAR)); header = HeapAlloc(GetProcessHeap(),0,headerlen*sizeof(WCHAR));
if (!(BuffersInW.lpcszHeader = header)) if (!(BuffersInW.lpcszHeader = header))
{ {
INTERNET_SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return FALSE; return FALSE;
} }
BuffersInW.dwHeadersLength = MultiByteToWideChar(CP_ACP, 0, BuffersInW.dwHeadersLength = MultiByteToWideChar(CP_ACP, 0,
...@@ -4203,30 +4203,25 @@ static const object_vtbl_t HTTPSESSIONVtbl = { ...@@ -4203,30 +4203,25 @@ static const object_vtbl_t HTTPSESSIONVtbl = {
* NULL on failure * NULL on failure
* *
*/ */
HINTERNET HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, DWORD HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
INTERNET_PORT nServerPort, LPCWSTR lpszUserName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
DWORD dwInternalFlags) DWORD dwInternalFlags, HINTERNET *ret)
{ {
http_session_t *lpwhs = NULL; http_session_t *lpwhs = NULL;
HINTERNET handle = NULL; HINTERNET handle = NULL;
DWORD res = ERROR_SUCCESS;
TRACE("-->\n"); TRACE("-->\n");
if (!lpszServerName || !lpszServerName[0]) if (!lpszServerName || !lpszServerName[0])
{ return ERROR_INVALID_PARAMETER;
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
goto lerror;
}
assert( hIC->hdr.htype == WH_HINIT ); assert( hIC->hdr.htype == WH_HINIT );
lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(http_session_t)); lpwhs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(http_session_t));
if (NULL == lpwhs) if (!lpwhs)
{ return ERROR_OUTOFMEMORY;
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
goto lerror;
}
/* /*
* According to my tests. The name is not resolved until a request is sent * According to my tests. The name is not resolved until a request is sent
...@@ -4248,8 +4243,8 @@ HINTERNET HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, ...@@ -4248,8 +4243,8 @@ HINTERNET HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
if (NULL == handle) if (NULL == handle)
{ {
ERR("Failed to alloc handle\n"); ERR("Failed to alloc handle\n");
INTERNET_SetLastError(ERROR_OUTOFMEMORY); res = ERROR_OUTOFMEMORY;
goto lerror; goto lerror;
} }
if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) { if(hIC->lpszProxy && hIC->dwAccessType == INTERNET_OPEN_TYPE_PROXY) {
...@@ -4288,7 +4283,10 @@ lerror: ...@@ -4288,7 +4283,10 @@ lerror:
*/ */
TRACE("%p --> %p (%p)\n", hIC, handle, lpwhs); TRACE("%p --> %p (%p)\n", hIC, handle, lpwhs);
return handle;
if(res == ERROR_SUCCESS)
*ret = handle;
return res;
} }
......
...@@ -949,6 +949,7 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, ...@@ -949,6 +949,7 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
{ {
appinfo_t *hIC; appinfo_t *hIC;
HINTERNET rc = NULL; HINTERNET rc = NULL;
DWORD res = ERROR_SUCCESS;
TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName), TRACE("(%p, %s, %i, %s, %s, %i, %i, %lx)\n", hInternet, debugstr_w(lpszServerName),
nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword), nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword),
...@@ -956,16 +957,14 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, ...@@ -956,16 +957,14 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
if (!lpszServerName) if (!lpszServerName)
{ {
INTERNET_SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return NULL; return NULL;
} }
/* Clear any error information */
INTERNET_SetLastError(0);
hIC = (appinfo_t*)WININET_GetObject( hInternet ); hIC = (appinfo_t*)WININET_GetObject( hInternet );
if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) ) if ( (hIC == NULL) || (hIC->hdr.htype != WH_HINIT) )
{ {
INTERNET_SetLastError(ERROR_INVALID_HANDLE); res = ERROR_INVALID_HANDLE;
goto lend; goto lend;
} }
...@@ -974,11 +973,13 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet, ...@@ -974,11 +973,13 @@ HINTERNET WINAPI InternetConnectW(HINTERNET hInternet,
case INTERNET_SERVICE_FTP: case INTERNET_SERVICE_FTP:
rc = FTP_Connect(hIC, lpszServerName, nServerPort, rc = FTP_Connect(hIC, lpszServerName, nServerPort,
lpszUserName, lpszPassword, dwFlags, dwContext, 0); lpszUserName, lpszPassword, dwFlags, dwContext, 0);
if(!rc)
res = INTERNET_GetLastError();
break; break;
case INTERNET_SERVICE_HTTP: case INTERNET_SERVICE_HTTP:
rc = HTTP_Connect(hIC, lpszServerName, nServerPort, res = HTTP_Connect(hIC, lpszServerName, nServerPort,
lpszUserName, lpszPassword, dwFlags, dwContext, 0); lpszUserName, lpszPassword, dwFlags, dwContext, 0, &rc);
break; break;
case INTERNET_SERVICE_GOPHER: case INTERNET_SERVICE_GOPHER:
...@@ -990,6 +991,7 @@ lend: ...@@ -990,6 +991,7 @@ lend:
WININET_Release( &hIC->hdr ); WININET_Release( &hIC->hdr );
TRACE("returning %p\n", rc); TRACE("returning %p\n", rc);
SetLastError(res);
return rc; return rc;
} }
...@@ -2835,6 +2837,7 @@ static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl, ...@@ -2835,6 +2837,7 @@ static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024]; WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
WCHAR password[1024], path[2048], extra[1024]; WCHAR password[1024], path[2048], extra[1024];
HINTERNET client = NULL, client1 = NULL; HINTERNET client = NULL, client1 = NULL;
DWORD res;
TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders), TRACE("(%p, %s, %s, %08x, %08x, %08lx)\n", hIC, debugstr_w(lpszUrl), debugstr_w(lpszHeaders),
dwHeadersLength, dwFlags, dwContext); dwHeadersLength, dwFlags, dwContext);
...@@ -2882,10 +2885,12 @@ static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl, ...@@ -2882,10 +2885,12 @@ static HINTERNET INTERNET_InternetOpenUrlW(appinfo_t *hIC, LPCWSTR lpszUrl,
if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE; if (urlComponents.nScheme == INTERNET_SCHEME_HTTPS) dwFlags |= INTERNET_FLAG_SECURE;
/* FIXME: should use pointers, not handles, as handles are not thread-safe */ /* FIXME: should use pointers, not handles, as handles are not thread-safe */
client = HTTP_Connect(hIC, hostName, urlComponents.nPort, res = HTTP_Connect(hIC, hostName, urlComponents.nPort,
userName, password, dwFlags, dwContext, INET_OPENURL); userName, password, dwFlags, dwContext, INET_OPENURL, &client);
if(client == NULL) if(res != ERROR_SUCCESS) {
INTERNET_SetLastError(res);
break; break;
}
if (urlComponents.dwExtraInfoLength) { if (urlComponents.dwExtraInfoLength) {
WCHAR *path_extra; WCHAR *path_extra;
......
...@@ -397,10 +397,10 @@ HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, ...@@ -397,10 +397,10 @@ HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
DWORD dwInternalFlags); DWORD dwInternalFlags);
HINTERNET HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, DWORD HTTP_Connect(appinfo_t*,LPCWSTR,
INTERNET_PORT nServerPort, LPCWSTR lpszUserName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
DWORD dwInternalFlags); DWORD dwInternalFlags, HINTERNET*);
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort, BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
struct sockaddr *psa, socklen_t *sa_len); struct sockaddr *psa, socklen_t *sa_len);
......
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