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

wininet: Handles handling clean up.

parent e1815f5e
......@@ -70,7 +70,7 @@ static BOOL WININET_GetProxyServer( HINTERNET hRequest, LPWSTR szBuf, DWORD sz )
BOOL ret = FALSE;
LPWSTR p;
lpwhr = (http_request_t*) WININET_GetObject( hRequest );
lpwhr = (http_request_t*) get_handle_object( hRequest );
if (NULL == lpwhr)
return FALSE;
......@@ -107,7 +107,7 @@ static BOOL WININET_GetServer( HINTERNET hRequest, LPWSTR szBuf, DWORD sz )
http_session_t *lpwhs = NULL;
BOOL ret = FALSE;
lpwhr = (http_request_t*) WININET_GetObject( hRequest );
lpwhr = (http_request_t*) get_handle_object( hRequest );
if (NULL == lpwhr)
return FALSE;
......@@ -246,7 +246,7 @@ static BOOL WININET_SetAuthorization( HINTERNET hRequest, LPWSTR username,
BOOL ret = FALSE;
LPWSTR p, q;
lpwhr = (http_request_t*) WININET_GetObject( hRequest );
lpwhr = (http_request_t*) get_handle_object( hRequest );
if( !lpwhr )
return FALSE;
......
......@@ -288,7 +288,7 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
return FALSE;
}
lpwfs = (ftp_session_t*) WININET_GetObject( hConnect );
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -470,7 +470,7 @@ BOOL WINAPI FtpSetCurrentDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
goto lend;
}
lpwfs = (ftp_session_t*) WININET_GetObject( hConnect );
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
{
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
......@@ -610,7 +610,7 @@ BOOL WINAPI FtpCreateDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
appinfo_t *hIC = NULL;
BOOL r = FALSE;
lpwfs = (ftp_session_t*) WININET_GetObject( hConnect );
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -766,7 +766,7 @@ HINTERNET WINAPI FtpFindFirstFileW(HINTERNET hConnect,
appinfo_t *hIC = NULL;
HINTERNET r = NULL;
lpwfs = (ftp_session_t*) WININET_GetObject( hConnect );
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
{
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
......@@ -964,7 +964,7 @@ BOOL WINAPI FtpGetCurrentDirectoryW(HINTERNET hFtpSession, LPWSTR lpszCurrentDir
TRACE("%p %p %p\n", hFtpSession, lpszCurrentDirectory, lpdwCurrentDirectory);
lpwfs = (ftp_session_t*) WININET_GetObject( hFtpSession );
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
if (NULL == lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -1327,6 +1327,7 @@ static HINTERNET FTP_FtpOpenFileW(ftp_session_t *lpwfs,
ftp_file_t *lpwh = NULL;
appinfo_t *hIC = NULL;
HINTERNET handle = NULL;
DWORD res = ERROR_SUCCESS;
TRACE("\n");
......@@ -1364,8 +1365,8 @@ static HINTERNET FTP_FtpOpenFileW(ftp_session_t *lpwfs,
lpwh->lpFtpSession = lpwfs;
list_add_head( &lpwfs->hdr.children, &lpwh->hdr.entry );
handle = WININET_AllocHandle( &lpwh->hdr );
if( !handle )
res = alloc_handle(&lpwh->hdr, &handle);
if (res != ERROR_SUCCESS)
goto lend;
/* Indicate that a download is currently in progress */
......@@ -1440,6 +1441,8 @@ lend:
if( lpwh )
WININET_Release( &lpwh->hdr );
if(res != ERROR_SUCCESS)
INTERNET_SetLastError(res);
return handle;
}
......@@ -1501,7 +1504,7 @@ HINTERNET WINAPI FtpOpenFileW(HINTERNET hFtpSession,
TRACE("(%p,%s,0x%08x,0x%08x,0x%08lx)\n", hFtpSession,
debugstr_w(lpszFileName), fdwAccess, dwFlags, dwContext);
lpwfs = (ftp_session_t*) WININET_GetObject( hFtpSession );
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -1624,7 +1627,7 @@ BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lps
return FALSE;
}
lpwfs = (ftp_session_t*) WININET_GetObject( hInternet );
lpwfs = (ftp_session_t*) get_handle_object( hInternet );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -1818,7 +1821,7 @@ BOOL WINAPI FtpDeleteFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName)
appinfo_t *hIC = NULL;
BOOL r = FALSE;
lpwfs = (ftp_session_t*) WININET_GetObject( hFtpSession );
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -1963,7 +1966,7 @@ BOOL WINAPI FtpRemoveDirectoryW(HINTERNET hFtpSession, LPCWSTR lpszDirectory)
appinfo_t *hIC = NULL;
BOOL r = FALSE;
lpwfs = (ftp_session_t*) WININET_GetObject( hFtpSession );
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -2113,7 +2116,7 @@ BOOL WINAPI FtpRenameFileW(HINTERNET hFtpSession, LPCWSTR lpszSrc, LPCWSTR lpszD
appinfo_t *hIC = NULL;
BOOL r = FALSE;
lpwfs = (ftp_session_t*) WININET_GetObject( hFtpSession );
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -2279,7 +2282,7 @@ BOOL WINAPI FtpCommandW( HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags
return FALSE;
}
lpwfs = (ftp_session_t*) WININET_GetObject( hConnect );
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
......@@ -2451,6 +2454,7 @@ HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
ftp_session_t *lpwfs = NULL;
HINTERNET handle = NULL;
char szaddr[INET_ADDRSTRLEN];
DWORD res;
TRACE("%p Server(%s) Port(%d) User(%s) Paswd(%s)\n",
hIC, debugstr_w(lpszServerName),
......@@ -2492,11 +2496,11 @@ HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
lpwfs->lpAppInfo = hIC;
list_add_head( &hIC->hdr.children, &lpwfs->hdr.entry );
handle = WININET_AllocHandle( &lpwfs->hdr );
if( !handle )
res = alloc_handle(&lpwfs->hdr, &handle);
if(res != ERROR_SUCCESS)
{
ERR("Failed to alloc handle\n");
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
INTERNET_SetLastError(res);
goto lerror;
}
......@@ -2604,7 +2608,7 @@ lerror:
if (!bSuccess && handle)
{
WININET_FreeHandle( handle );
InternetCloseHandle(handle);
handle = NULL;
}
......@@ -3531,6 +3535,7 @@ static HINTERNET FTP_ReceiveFileList(ftp_session_t *lpwfs, INT nSocket, LPCWSTR
LPFILEPROPERTIESW lpafp = NULL;
LPWININETFTPFINDNEXTW lpwfn = NULL;
HINTERNET handle = 0;
DWORD res;
TRACE("(%p,%d,%s,%p,%08lx)\n", lpwfs, nSocket, debugstr_w(lpszSearchFile), lpFindFileData, dwContext);
......@@ -3555,7 +3560,9 @@ static HINTERNET FTP_ReceiveFileList(ftp_session_t *lpwfs, INT nSocket, LPCWSTR
lpwfn->lpFtpSession = lpwfs;
list_add_head( &lpwfs->hdr.children, &lpwfn->hdr.entry );
handle = WININET_AllocHandle( &lpwfn->hdr );
res = alloc_handle(&lpwfn->hdr, &handle);
if(res != ERROR_SUCCESS)
SetLastError(res);
}
}
......
......@@ -1066,7 +1066,7 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
if (!lpszHeader)
return TRUE;
lpwhr = (http_request_t*) WININET_GetObject( hHttpRequest );
lpwhr = (http_request_t*) get_handle_object( hHttpRequest );
if (lpwhr && lpwhr->hdr.htype == WH_HHTTPREQ)
res = HTTP_HttpAddRequestHeadersW( lpwhr, lpszHeader, dwHeaderLength, dwModifier );
if( lpwhr )
......@@ -2604,12 +2604,9 @@ static DWORD HTTP_HttpOpenRequestW(http_session_t *lpwhs,
goto lend;
}
handle = WININET_AllocHandle( &lpwhr->hdr );
if (NULL == handle)
{
res = ERROR_OUTOFMEMORY;
res = alloc_handle(&lpwhr->hdr, &handle);
if (res != ERROR_SUCCESS)
goto lend;
}
if ((res = NETCON_init(&lpwhr->netConnection, dwFlags & INTERNET_FLAG_SECURE)) != ERROR_SUCCESS)
{
......@@ -2727,7 +2724,7 @@ HINTERNET WINAPI HttpOpenRequestW(HINTERNET hHttpSession,
TRACE("\taccept type: %s\n",debugstr_w(lpszAcceptTypes[i]));
}
lpwhs = (http_session_t*) WININET_GetObject( hHttpSession );
lpwhs = (http_session_t*) get_handle_object( hHttpSession );
if (NULL == lpwhs || lpwhs->hdr.htype != WH_HHTTPSESSION)
{
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
......@@ -3174,7 +3171,7 @@ BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel,
TRACE("\n");
}
lpwhr = (http_request_t*) WININET_GetObject( hHttpRequest );
lpwhr = (http_request_t*) get_handle_object( hHttpRequest );
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
{
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
......@@ -4045,7 +4042,7 @@ BOOL WINAPI HttpEndRequestW(HINTERNET hRequest,
return FALSE;
}
lpwhr = (http_request_t*) WININET_GetObject( hRequest );
lpwhr = (http_request_t*) get_handle_object( hRequest );
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
{
......@@ -4160,7 +4157,7 @@ BOOL WINAPI HttpSendRequestExW(HINTERNET hRequest,
TRACE("(%p, %p, %p, %08x, %08lx)\n", hRequest, lpBuffersIn,
lpBuffersOut, dwFlags, dwContext);
lpwhr = (http_request_t*) WININET_GetObject( hRequest );
lpwhr = (http_request_t*) get_handle_object( hRequest );
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
{
......@@ -4259,7 +4256,7 @@ BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders,
TRACE("%p, %s, %i, %p, %i)\n", hHttpRequest,
debugstr_wn(lpszHeaders, dwHeaderLength), dwHeaderLength, lpOptional, dwOptionalLength);
lpwhr = (http_request_t*) WININET_GetObject( hHttpRequest );
lpwhr = (http_request_t*) get_handle_object( hHttpRequest );
if (NULL == lpwhr || lpwhr->hdr.htype != WH_HHTTPREQ)
{
res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
......@@ -4444,7 +4441,7 @@ DWORD HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
{
http_session_t *lpwhs = NULL;
HINTERNET handle = NULL;
DWORD res = ERROR_SUCCESS;
DWORD res;
TRACE("-->\n");
......@@ -4473,11 +4470,10 @@ DWORD HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
lpwhs->lpAppInfo = hIC;
list_add_head( &hIC->hdr.children, &lpwhs->hdr.entry );
handle = WININET_AllocHandle( &lpwhs->hdr );
if (NULL == handle)
res = alloc_handle(&lpwhs->hdr, &handle);
if (res != ERROR_SUCCESS)
{
ERR("Failed to alloc handle\n");
res = ERROR_OUTOFMEMORY;
goto lerror;
}
......
......@@ -58,6 +58,31 @@ typedef struct
DWORD security_flags;
} WININET_NETCONNECTION;
static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
{
return HeapAlloc(GetProcessHeap(), 0, len);
}
static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
{
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
}
static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
{
return HeapReAlloc(GetProcessHeap(), 0, mem, len);
}
static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
{
return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
}
static inline BOOL heap_free(void *mem)
{
return HeapFree(GetProcessHeap(), 0, mem);
}
static inline LPWSTR heap_strdupW(LPCWSTR str)
{
LPWSTR ret = NULL;
......@@ -409,11 +434,10 @@ typedef struct WORKREQ
} WORKREQUEST, *LPWORKREQUEST;
HINTERNET WININET_AllocHandle( object_header_t *info );
object_header_t *WININET_GetObject( HINTERNET hinternet );
DWORD alloc_handle( object_header_t*, HINTERNET*);
object_header_t *get_handle_object( HINTERNET hinternet );
object_header_t *WININET_AddRef( object_header_t *info );
BOOL WININET_Release( object_header_t *info );
BOOL WININET_FreeHandle( HINTERNET hinternet );
DWORD INET_QueryOption( object_header_t *, DWORD, void *, DWORD *, BOOL );
......
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