From 5a535d6b23b2f36a879e582475a237e44fc5de5b Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 26 Feb 2008 20:20:41 +0100 Subject: [PATCH] wininet: Moved handle destructor to vtbl. --- dlls/wininet/ftp.c | 126 +++++++++++++++++++----------------- dlls/wininet/http.c | 138 +++++++++++++++++++++------------------- dlls/wininet/internet.c | 54 ++++++++-------- dlls/wininet/internet.h | 6 +- 4 files changed, 171 insertions(+), 153 deletions(-) diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c index f9ae2dbb213..94a066664ac 100644 --- a/dlls/wininet/ftp.c +++ b/dlls/wininet/ftp.c @@ -122,10 +122,7 @@ static const CHAR *const szFtpCommands[] = { static const CHAR szMonths[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; static const WCHAR szNoAccount[] = {'n','o','a','c','c','o','u','n','t','\0'}; -static void FTP_CloseFileTransferHandle(LPWININETHANDLEHEADER hdr); -static void FTP_CloseSessionHandle(LPWININETHANDLEHEADER hdr); static void FTP_CloseConnection(LPWININETHANDLEHEADER hdr); -static void FTP_CloseFindNextHandle(LPWININETHANDLEHEADER hdr); static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, LPWININETHANDLEHEADER hdr, DWORD_PTR dwContext); static BOOL FTP_SendStore(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, DWORD dwType); @@ -1130,6 +1127,39 @@ lend: } +/*********************************************************************** + * FTPFILE_Destroy(internal) + * + * Closes the file transfer handle. This also 'cleans' the data queue of + * the 'transfer complete' message (this is a bit of a hack though :-/ ) + * + */ +static void FTPFILE_Destroy(WININETHANDLEHEADER *hdr) +{ + LPWININETFTPFILE lpwh = (LPWININETFTPFILE) hdr; + LPWININETFTPSESSIONW lpwfs = lpwh->lpFtpSession; + INT nResCode; + + TRACE("\n"); + + WININET_Release(&lpwh->lpFtpSession->hdr); + + if (!lpwh->session_deleted) + lpwfs->download_in_progress = NULL; + + if (lpwh->nDataSocket != -1) + closesocket(lpwh->nDataSocket); + + nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext); + if (nResCode > 0 && nResCode != 226) WARN("server reports failed transfer\n"); + + HeapFree(GetProcessHeap(), 0, lpwh); +} + +static const HANDLEHEADERVtbl FTPFILEVtbl = { + FTPFILE_Destroy +}; + /*********************************************************************** * FTP_FtpOpenFileW (Internal) * @@ -1171,11 +1201,11 @@ HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, { lpwh = HeapAlloc(GetProcessHeap(), 0, sizeof(WININETFTPFILE)); lpwh->hdr.htype = WH_HFILE; + lpwh->hdr.vtbl = &FTPFILEVtbl; lpwh->hdr.dwFlags = dwFlags; lpwh->hdr.dwContext = dwContext; lpwh->hdr.dwRefCount = 1; lpwh->hdr.close_connection = NULL; - lpwh->hdr.destroy = FTP_CloseFileTransferHandle; lpwh->hdr.lpfnStatusCB = lpwfs->hdr.lpfnStatusCB; lpwh->nDataSocket = nDataSocket; lpwh->session_deleted = FALSE; @@ -1998,6 +2028,31 @@ lend: return r; } + +/*********************************************************************** + * FTPSESSION_Destroy (internal) + * + * Deallocate session handle + */ +static void FTPSESSION_Destroy(WININETHANDLEHEADER *hdr) +{ + LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) hdr; + + TRACE("\n"); + + WININET_Release(&lpwfs->lpAppInfo->hdr); + + HeapFree(GetProcessHeap(), 0, lpwfs->lpszPassword); + HeapFree(GetProcessHeap(), 0, lpwfs->lpszUserName); + HeapFree(GetProcessHeap(), 0, lpwfs); +} + + +static const HANDLEHEADERVtbl FTPSESSIONVtbl = { + FTPSESSION_Destroy +}; + + /*********************************************************************** * FTP_Connect (internal) * @@ -2061,12 +2116,12 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, nServerPort = INTERNET_DEFAULT_FTP_PORT; lpwfs->hdr.htype = WH_HFTPSESSION; + lpwfs->hdr.vtbl = &FTPSESSIONVtbl; lpwfs->hdr.dwFlags = dwFlags; lpwfs->hdr.dwContext = dwContext; lpwfs->hdr.dwInternalFlags = dwInternalFlags; lpwfs->hdr.dwRefCount = 1; lpwfs->hdr.close_connection = FTP_CloseConnection; - lpwfs->hdr.destroy = FTP_CloseSessionHandle; lpwfs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB; lpwfs->download_in_progress = NULL; lpwfs->sndSocket = -1; @@ -3021,25 +3076,6 @@ static void FTP_CloseConnection(LPWININETHANDLEHEADER hdr) } -/*********************************************************************** - * FTP_CloseSessionHandle (internal) - * - * Deallocate session handle - */ -static void FTP_CloseSessionHandle(LPWININETHANDLEHEADER hdr) -{ - LPWININETFTPSESSIONW lpwfs = (LPWININETFTPSESSIONW) hdr; - - TRACE("\n"); - - WININET_Release(&lpwfs->lpAppInfo->hdr); - - HeapFree(GetProcessHeap(), 0, lpwfs->lpszPassword); - HeapFree(GetProcessHeap(), 0, lpwfs->lpszUserName); - HeapFree(GetProcessHeap(), 0, lpwfs); -} - - /*********************************************************************** * FTP_FindNextFileW (Internal) * @@ -3097,16 +3133,11 @@ lend: /*********************************************************************** - * FTP_CloseFindNextHandle (internal) + * FTPFINDNEXT_Destroy (internal) * * Deallocate session handle - * - * RETURNS - * TRUE on success - * FALSE on failure - * */ -static void FTP_CloseFindNextHandle(LPWININETHANDLEHEADER hdr) +static void FTPFINDNEXT_Destroy(WININETHANDLEHEADER *hdr) { LPWININETFTPFINDNEXTW lpwfn = (LPWININETFTPFINDNEXTW) hdr; DWORD i; @@ -3124,34 +3155,9 @@ static void FTP_CloseFindNextHandle(LPWININETHANDLEHEADER hdr) HeapFree(GetProcessHeap(), 0, lpwfn); } -/*********************************************************************** - * FTP_CloseFileTransferHandle (internal) - * - * Closes the file transfer handle. This also 'cleans' the data queue of - * the 'transfer complete' message (this is a bit of a hack though :-/ ) - * - */ -static void FTP_CloseFileTransferHandle(LPWININETHANDLEHEADER hdr) -{ - LPWININETFTPFILE lpwh = (LPWININETFTPFILE) hdr; - LPWININETFTPSESSIONW lpwfs = lpwh->lpFtpSession; - INT nResCode; - - TRACE("\n"); - - WININET_Release(&lpwh->lpFtpSession->hdr); - - if (!lpwh->session_deleted) - lpwfs->download_in_progress = NULL; - - if (lpwh->nDataSocket != -1) - closesocket(lpwh->nDataSocket); - - nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext); - if (nResCode > 0 && nResCode != 226) WARN("server reports failed transfer\n"); - - HeapFree(GetProcessHeap(), 0, lpwh); -} +static const HANDLEHEADERVtbl FTPFINDNEXTVtbl = { + FTPFINDNEXT_Destroy +}; /*********************************************************************** * FTP_ReceiveFileList (internal) @@ -3182,10 +3188,10 @@ static HINTERNET FTP_ReceiveFileList(LPWININETFTPSESSIONW lpwfs, INT nSocket, LP if (lpwfn) { lpwfn->hdr.htype = WH_HFTPFINDNEXT; + lpwfn->hdr.vtbl = &FTPFINDNEXTVtbl; lpwfn->hdr.dwContext = dwContext; lpwfn->hdr.dwRefCount = 1; lpwfn->hdr.close_connection = NULL; - lpwfn->hdr.destroy = FTP_CloseFindNextHandle; lpwfn->hdr.lpfnStatusCB = lpwfs->hdr.lpfnStatusCB; lpwfn->index = 1; /* Next index is 1 since we return index 0 */ lpwfn->size = dwSize; diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 478763ecbc1..c9fa5e0d543 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -104,8 +104,6 @@ struct HttpAuthInfo }; static void HTTP_CloseConnection(LPWININETHANDLEHEADER hdr); -static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr); -static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr); static BOOL HTTP_OpenConnection(LPWININETHTTPREQW lpwhr); static BOOL HTTP_GetResponseHeaders(LPWININETHTTPREQW lpwhr); static BOOL HTTP_ProcessHeader(LPWININETHTTPREQW lpwhr, LPCWSTR field, LPCWSTR value, DWORD dwModifier); @@ -1311,6 +1309,50 @@ static BOOL HTTP_ResolveName(LPWININETHTTPREQW lpwhr) return TRUE; } + +/*********************************************************************** + * HTTPREQ_Destroy (internal) + * + * Deallocate request handle + * + */ +static void HTTPREQ_Destroy(WININETHANDLEHEADER *hdr) +{ + LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr; + DWORD i; + + TRACE("\n"); + + if(lpwhr->hCacheFile) + CloseHandle(lpwhr->hCacheFile); + + if(lpwhr->lpszCacheFile) { + DeleteFileW(lpwhr->lpszCacheFile); /* FIXME */ + HeapFree(GetProcessHeap(), 0, lpwhr->lpszCacheFile); + } + + WININET_Release(&lpwhr->lpHttpSession->hdr); + + HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); + HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb); + HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); + HeapFree(GetProcessHeap(), 0, lpwhr->lpszVersion); + HeapFree(GetProcessHeap(), 0, lpwhr->lpszStatusText); + + for (i = 0; i < lpwhr->nCustHeaders; i++) + { + HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField); + HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue); + } + + HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders); + HeapFree(GetProcessHeap(), 0, lpwhr); +} + +static const HANDLEHEADERVtbl HTTPREQVtbl = { + HTTPREQ_Destroy +}; + /*********************************************************************** * HTTP_HttpOpenRequestW (internal) * @@ -1348,11 +1390,11 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs, goto lend; } lpwhr->hdr.htype = WH_HHTTPREQ; + lpwhr->hdr.vtbl = &HTTPREQVtbl; lpwhr->hdr.dwFlags = dwFlags; lpwhr->hdr.dwContext = dwContext; lpwhr->hdr.dwRefCount = 1; lpwhr->hdr.close_connection = HTTP_CloseConnection; - lpwhr->hdr.destroy = HTTP_CloseHTTPRequestHandle; lpwhr->hdr.lpfnStatusCB = lpwhs->hdr.lpfnStatusCB; lpwhr->hdr.dwInternalFlags = lpwhs->hdr.dwInternalFlags & INET_CALLBACKW; @@ -2807,6 +2849,33 @@ lend: return bSuccess; } +/*********************************************************************** + * HTTPSESSION_Destroy (internal) + * + * Deallocate session handle + * + */ +static void HTTPSESSION_Destroy(WININETHANDLEHEADER *hdr) +{ + LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) hdr; + + TRACE("%p\n", lpwhs); + + WININET_Release(&lpwhs->lpAppInfo->hdr); + + HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName); + HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); + HeapFree(GetProcessHeap(), 0, lpwhs->lpszPassword); + HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName); + HeapFree(GetProcessHeap(), 0, lpwhs); +} + + +static const HANDLEHEADERVtbl HTTPSESSIONVtbl = { + HTTPSESSION_Destroy +}; + + /*********************************************************************** * HTTP_Connect (internal) * @@ -2848,12 +2917,12 @@ HINTERNET HTTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, */ lpwhs->hdr.htype = WH_HHTTPSESSION; + lpwhs->hdr.vtbl = &HTTPSESSIONVtbl; lpwhs->hdr.dwFlags = dwFlags; lpwhs->hdr.dwContext = dwContext; lpwhs->hdr.dwInternalFlags = dwInternalFlags | (hIC->hdr.dwInternalFlags & INET_CALLBACKW); lpwhs->hdr.dwRefCount = 1; lpwhs->hdr.close_connection = NULL; - lpwhs->hdr.destroy = HTTP_CloseHTTPSessionHandle; lpwhs->hdr.lpfnStatusCB = hIC->hdr.lpfnStatusCB; WININET_AddRef( &hIC->hdr ); @@ -3436,67 +3505,6 @@ BOOL HTTP_FinishedReading(LPWININETHTTPREQW lpwhr) return TRUE; } -/*********************************************************************** - * HTTP_CloseHTTPRequestHandle (internal) - * - * Deallocate request handle - * - */ -static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr) -{ - DWORD i; - LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW) hdr; - - TRACE("\n"); - - if(lpwhr->hCacheFile) - CloseHandle(lpwhr->hCacheFile); - - if(lpwhr->lpszCacheFile) { - DeleteFileW(lpwhr->lpszCacheFile); /* FIXME */ - HeapFree(GetProcessHeap(), 0, lpwhr->lpszCacheFile); - } - - WININET_Release(&lpwhr->lpHttpSession->hdr); - - HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath); - HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb); - HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders); - HeapFree(GetProcessHeap(), 0, lpwhr->lpszVersion); - HeapFree(GetProcessHeap(), 0, lpwhr->lpszStatusText); - - for (i = 0; i < lpwhr->nCustHeaders; i++) - { - HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszField); - HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders[i].lpszValue); - } - - HeapFree(GetProcessHeap(), 0, lpwhr->pCustHeaders); - HeapFree(GetProcessHeap(), 0, lpwhr); -} - - -/*********************************************************************** - * HTTP_CloseHTTPSessionHandle (internal) - * - * Deallocate session handle - * - */ -static void HTTP_CloseHTTPSessionHandle(LPWININETHANDLEHEADER hdr) -{ - LPWININETHTTPSESSIONW lpwhs = (LPWININETHTTPSESSIONW) hdr; - - TRACE("%p\n", lpwhs); - - WININET_Release(&lpwhs->lpAppInfo->hdr); - - HeapFree(GetProcessHeap(), 0, lpwhs->lpszHostName); - HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName); - HeapFree(GetProcessHeap(), 0, lpwhs->lpszPassword); - HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName); - HeapFree(GetProcessHeap(), 0, lpwhs); -} - /*********************************************************************** * HTTP_GetCustomHeaderIndex (internal) diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 405371ada2b..3d605f90695 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -78,7 +78,6 @@ typedef struct CHAR response[MAX_REPLY_LEN]; } WITHREADERROR, *LPWITHREADERROR; -static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr); HINTERNET WINAPI INTERNET_InternetOpenUrlW(LPWININETAPPINFOW hIC, LPCWSTR lpszUrl, LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD_PTR dwContext); @@ -186,7 +185,7 @@ BOOL WININET_Release( LPWININETHANDLEHEADER info ) TRACE( "destroying object %p\n", info); if ( info->htype != WH_HINIT ) list_remove( &info->entry ); - info->destroy( info ); + info->vtbl->Destroy( info ); } return TRUE; } @@ -452,6 +451,31 @@ static void dump_INTERNET_FLAGS(DWORD dwFlags) TRACE("\n"); } +/*********************************************************************** + * INTERNET_CloseHandle (internal) + * + * Close internet handle + * + */ +static VOID APPINFO_Destroy(WININETHANDLEHEADER *hdr) +{ + LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr; + + TRACE("%p\n",lpwai); + + HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent); + HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy); + HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass); + HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername); + HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword); + HeapFree(GetProcessHeap(), 0, lpwai); +} + +static const HANDLEHEADERVtbl APPINFOVtbl = { + APPINFO_Destroy +}; + + /*********************************************************************** * InternetOpenW (WININET.@) * @@ -504,10 +528,10 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, } lpwai->hdr.htype = WH_HINIT; + lpwai->hdr.vtbl = &APPINFOVtbl; lpwai->hdr.dwFlags = dwFlags; lpwai->hdr.dwRefCount = 1; lpwai->hdr.close_connection = NULL; - lpwai->hdr.destroy = INTERNET_CloseHandle; lpwai->dwAccessType = dwAccessType; lpwai->lpszProxyUsername = NULL; lpwai->lpszProxyPassword = NULL; @@ -967,30 +991,6 @@ lend: return bSuccess; } -/*********************************************************************** - * INTERNET_CloseHandle (internal) - * - * Close internet handle - * - * RETURNS - * Void - * - */ -static VOID INTERNET_CloseHandle(LPWININETHANDLEHEADER hdr) -{ - LPWININETAPPINFOW lpwai = (LPWININETAPPINFOW) hdr; - - TRACE("%p\n",lpwai); - - HeapFree(GetProcessHeap(), 0, lpwai->lpszAgent); - HeapFree(GetProcessHeap(), 0, lpwai->lpszProxy); - HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyBypass); - HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyUsername); - HeapFree(GetProcessHeap(), 0, lpwai->lpszProxyPassword); - HeapFree(GetProcessHeap(), 0, lpwai); -} - - /*********************************************************************** * InternetCloseHandle (WININET.@) * diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h index b80de883b6e..514853abb9c 100644 --- a/dlls/wininet/internet.h +++ b/dlls/wininet/internet.h @@ -138,9 +138,14 @@ typedef struct _WININETHANDLEHEADER WININETHANDLEHEADER, *LPWININETHANDLEHEADER; typedef void (*WININET_object_function)( LPWININETHANDLEHEADER ); +typedef struct { + void (*Destroy)(WININETHANDLEHEADER*); +} HANDLEHEADERVtbl; + struct _WININETHANDLEHEADER { WH_TYPE htype; + const HANDLEHEADERVtbl *vtbl; HINTERNET hInternet; DWORD dwFlags; DWORD_PTR dwContext; @@ -148,7 +153,6 @@ struct _WININETHANDLEHEADER DWORD dwInternalFlags; DWORD dwRefCount; WININET_object_function close_connection; - WININET_object_function destroy; INTERNET_STATUS_CALLBACK lpfnStatusCB; struct list entry; struct list children;