Commit 3b4ca69e authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Move InternetReadFile to vtbl.

parent 9a5c0461
......@@ -1174,6 +1174,21 @@ static void FTPFILE_Destroy(WININETHANDLEHEADER *hdr)
HeapFree(GetProcessHeap(), 0, lpwh);
}
static DWORD FTPFILE_ReadFile(WININETHANDLEHEADER *hdr, void *buffer, DWORD size, DWORD *read)
{
WININETFTPFILE *file = (WININETFTPFILE*)hdr;
int res;
if (file->nDataSocket == -1)
return ERROR_INTERNET_DISCONNECTED;
/* FIXME: FTP should use NETCON_ stuff */
res = recv(file->nDataSocket, buffer, size, MSG_WAITALL);
*read = res>0 ? res : 0;
return res>=0 ? ERROR_SUCCESS : INTERNET_ERROR_BASE; /* FIXME*/
}
static BOOL FTPFILE_WriteFile(WININETHANDLEHEADER *hdr, const void *buffer, DWORD size, DWORD *written)
{
LPWININETFTPFILE lpwh = (LPWININETFTPFILE) hdr;
......@@ -1189,6 +1204,7 @@ static const HANDLEHEADERVtbl FTPFILEVtbl = {
FTPFILE_Destroy,
NULL,
NULL,
FTPFILE_ReadFile,
FTPFILE_WriteFile,
NULL,
NULL
......@@ -2111,6 +2127,7 @@ static const HANDLEHEADERVtbl FTPSESSIONVtbl = {
NULL,
NULL,
NULL,
NULL,
NULL
};
......@@ -3197,6 +3214,7 @@ static const HANDLEHEADERVtbl FTPFINDNEXTVtbl = {
NULL,
NULL,
NULL,
NULL,
FTPFINDNEXT_FindNextFileW
};
......
......@@ -1410,6 +1410,46 @@ static DWORD HTTPREQ_SetOption(WININETHANDLEHEADER *hdr, DWORD option, void *buf
return ERROR_INTERNET_INVALID_OPTION;
}
DWORD HTTPREQ_Read(WININETHTTPREQW *req, void *buffer, DWORD size, DWORD *read, BOOL sync)
{
int bytes_read;
if(!NETCON_recv(&req->netConnection, buffer, min(size, req->dwContentLength - req->dwContentRead),
sync ? MSG_WAITALL : 0, &bytes_read)) {
if(req->dwContentLength != -1 && req->dwContentRead != req->dwContentLength)
ERR("not all data received %d/%d\n", req->dwContentRead, req->dwContentLength);
/* always returns TRUE, even if the network layer returns an
* error */
*read = 0;
HTTP_FinishedReading(req);
return ERROR_SUCCESS;
}
req->dwContentRead += bytes_read;
*read = bytes_read;
if(req->lpszCacheFile) {
BOOL res;
res = WriteFile(req->hCacheFile, buffer, bytes_read, NULL, NULL);
if(!res)
WARN("WriteFile failed: %u\n", GetLastError());
}
if(!bytes_read && (req->dwContentRead == req->dwContentLength))
HTTP_FinishedReading(req);
return ERROR_SUCCESS;
}
static DWORD HTTPREQ_ReadFile(WININETHANDLEHEADER *hdr, void *buffer, DWORD size, DWORD *read)
{
WININETHTTPREQW *req = (WININETHTTPREQW*)hdr;
return HTTPREQ_Read(req, buffer, size, read, TRUE);
}
static BOOL HTTPREQ_WriteFile(WININETHANDLEHEADER *hdr, const void *buffer, DWORD size, DWORD *written)
{
LPWININETHTTPREQW lpwhr = (LPWININETHTTPREQW)hdr;
......@@ -1471,6 +1511,7 @@ static const HANDLEHEADERVtbl HTTPREQVtbl = {
HTTPREQ_Destroy,
HTTPREQ_CloseConnection,
HTTPREQ_SetOption,
HTTPREQ_ReadFile,
HTTPREQ_WriteFile,
HTTPREQ_QueryDataAvailable,
NULL
......@@ -2999,6 +3040,7 @@ static const HANDLEHEADERVtbl HTTPSESSIONVtbl = {
NULL,
NULL,
NULL,
NULL,
NULL
};
......
......@@ -477,6 +477,7 @@ static const HANDLEHEADERVtbl APPINFOVtbl = {
NULL,
NULL,
NULL,
NULL,
NULL
};
......@@ -1703,11 +1704,9 @@ BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead, BOOL bWait)
{
BOOL retval = FALSE;
int nSocket = -1;
int bytes_read;
LPWININETHTTPREQW lpwhr;
/* FIXME: this should use NETCON functions! */
switch (lpwh->htype)
{
case WH_HHTTPREQ:
......@@ -1749,17 +1748,6 @@ BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
}
break;
case WH_HFILE:
/* FIXME: FTP should use NETCON_ stuff */
nSocket = ((LPWININETFTPFILE)lpwh)->nDataSocket;
if (nSocket != -1)
{
int res = recv(nSocket, lpBuffer, dwNumOfBytesToRead, bWait ? MSG_WAITALL : 0);
retval = (res >= 0);
*pdwNumOfBytesRead = retval ? res : 0;
}
break;
default:
break;
}
......@@ -1778,25 +1766,30 @@ BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
*
*/
BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer,
DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
DWORD dwNumOfBytesToRead, LPDWORD pdwNumOfBytesRead)
{
LPWININETHANDLEHEADER lpwh;
BOOL retval;
LPWININETHANDLEHEADER hdr;
DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE;
TRACE("%p %p %d %p\n", hFile, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
lpwh = WININET_GetObject( hFile );
if (!lpwh)
{
hdr = WININET_GetObject(hFile);
if (!hdr) {
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
retval = INTERNET_ReadFile(lpwh, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead, TRUE);
WININET_Release( lpwh );
if(hdr->vtbl->ReadFile)
res = hdr->vtbl->ReadFile(hdr, lpBuffer, dwNumOfBytesToRead, pdwNumOfBytesRead);
TRACE("-- %s (bytes read: %d)\n", retval ? "TRUE": "FALSE", pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
return retval;
WININET_Release(hdr);
TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res,
pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1);
if(res != ERROR_SUCCESS)
SetLastError(res);
return res == ERROR_SUCCESS;
}
/***********************************************************************
......
......@@ -139,6 +139,7 @@ typedef struct {
void (*Destroy)(WININETHANDLEHEADER*);
void (*CloseConnection)(WININETHANDLEHEADER*);
DWORD (*SetOption)(WININETHANDLEHEADER*,DWORD,void*,DWORD);
DWORD (*ReadFile)(WININETHANDLEHEADER*,void*,DWORD,DWORD*);
BOOL (*WriteFile)(WININETHANDLEHEADER*,const void*,DWORD,DWORD*);
DWORD (*QueryDataAvailable)(WININETHANDLEHEADER*,DWORD*,DWORD,DWORD_PTR);
DWORD (*FindNextFileW)(WININETHANDLEHEADER*,void*);
......
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