wininet: Moved handle destructor to vtbl.

This commit is contained in:
Jacek Caban 2008-02-26 20:20:41 +01:00 committed by Alexandre Julliard
parent 928c9f0984
commit 5a535d6b23
4 changed files with 171 additions and 153 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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.@)
*

View File

@ -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;