📄 internet.c
字号:
default:
break;
}
lend:
if( hIC )
WININET_Release( &hIC->hdr );
TRACE("returning %p\n", rc);
return rc;
}
/***********************************************************************
* InternetConnectA (WININET.@)
*
* Open a ftp, gopher or http session
*
* RETURNS
* HINTERNET a session handle on success
* NULL on failure
*
*/
HINTERNET WINAPI InternetConnectA(HINTERNET hInternet,
LPCSTR lpszServerName, INTERNET_PORT nServerPort,
LPCSTR lpszUserName, LPCSTR lpszPassword,
DWORD dwService, DWORD dwFlags, DWORD dwContext)
{
HINTERNET rc = (HINTERNET)NULL;
INT len = 0;
LPWSTR szServerName = NULL;
LPWSTR szUserName = NULL;
LPWSTR szPassword = NULL;
if (lpszServerName)
{
len = MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, NULL, 0);
szServerName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, lpszServerName, -1, szServerName, len);
}
if (lpszUserName)
{
len = MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, NULL, 0);
szUserName = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, lpszUserName, -1, szUserName, len);
}
if (lpszPassword)
{
len = MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, NULL, 0);
szPassword = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, lpszPassword, -1, szPassword, len);
}
rc = InternetConnectW(hInternet, szServerName, nServerPort,
szUserName, szPassword, dwService, dwFlags, dwContext);
HeapFree(GetProcessHeap(), 0, szServerName);
HeapFree(GetProcessHeap(), 0, szUserName);
HeapFree(GetProcessHeap(), 0, szPassword);
return rc;
}
/***********************************************************************
* InternetFindNextFileA (WININET.@)
*
* Continues a file search from a previous call to FindFirstFile
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetFindNextFileA(HINTERNET hFind, LPVOID lpvFindData)
{
BOOL ret;
WIN32_FIND_DATAW fd;
ret = InternetFindNextFileW(hFind, lpvFindData?&fd:NULL);
if(lpvFindData)
WININET_find_data_WtoA(&fd, (LPWIN32_FIND_DATAA)lpvFindData);
return ret;
}
/***********************************************************************
* InternetFindNextFileW (WININET.@)
*
* Continues a file search from a previous call to FindFirstFile
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetFindNextFileW(HINTERNET hFind, LPVOID lpvFindData)
{
LPWININETAPPINFOW hIC = NULL;
LPWININETFINDNEXTW lpwh;
BOOL bSuccess = FALSE;
TRACE("\n");
lpwh = (LPWININETFINDNEXTW) WININET_GetObject( hFind );
if (NULL == lpwh || lpwh->hdr.htype != WH_HFINDNEXT)
{
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
goto lend;
}
hIC = GET_HWININET_FROM_LPWININETFINDNEXT(lpwh);
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
{
WORKREQUEST workRequest;
struct WORKREQ_INTERNETFINDNEXTW *req;
workRequest.asyncall = INTERNETFINDNEXTW;
workRequest.hdr = WININET_AddRef( &lpwh->hdr );
req = &workRequest.u.InternetFindNextW;
req->lpFindFileData = lpvFindData;
bSuccess = INTERNET_AsyncCall(&workRequest);
}
else
{
bSuccess = INTERNET_FindNextFileW(lpwh, lpvFindData);
}
lend:
if( lpwh )
WININET_Release( &lpwh->hdr );
return bSuccess;
}
/***********************************************************************
* INTERNET_FindNextFileW (Internal)
*
* Continues a file search from a previous call to FindFirstFile
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI INTERNET_FindNextFileW(LPWININETFINDNEXTW lpwh, LPVOID lpvFindData)
{
BOOL bSuccess = TRUE;
LPWIN32_FIND_DATAW lpFindFileData;
TRACE("\n");
assert (lpwh->hdr.htype == WH_HFINDNEXT);
/* Clear any error information */
INTERNET_SetLastError(0);
if (lpwh->hdr.lpwhparent->htype != WH_HFTPSESSION)
{
FIXME("Only FTP find next supported\n");
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
return FALSE;
}
TRACE("index(%ld) size(%ld)\n", lpwh->index, lpwh->size);
lpFindFileData = (LPWIN32_FIND_DATAW) lpvFindData;
ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
if (lpwh->index >= lpwh->size)
{
INTERNET_SetLastError(ERROR_NO_MORE_FILES);
bSuccess = FALSE;
goto lend;
}
FTP_ConvertFileProp(&lpwh->lpafp[lpwh->index], lpFindFileData);
lpwh->index++;
TRACE("\nName: %s\nSize: %ld\n", debugstr_w(lpFindFileData->cFileName), lpFindFileData->nFileSizeLow);
lend:
if (lpwh->hdr.dwFlags & INTERNET_FLAG_ASYNC)
{
INTERNET_ASYNC_RESULT iar;
iar.dwResult = (DWORD)bSuccess;
iar.dwError = iar.dwError = bSuccess ? ERROR_SUCCESS :
INTERNET_GetLastError();
INTERNET_SendCallback(&lpwh->hdr, lpwh->hdr.dwContext,
INTERNET_STATUS_REQUEST_COMPLETE, &iar,
sizeof(INTERNET_ASYNC_RESULT));
}
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.@)
*
* Generic close handle function
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetCloseHandle(HINTERNET hInternet)
{
LPWININETHANDLEHEADER lpwh;
TRACE("%p\n",hInternet);
lpwh = WININET_GetObject( hInternet );
if (NULL == lpwh)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
/* FIXME: native appears to send this from the equivalent of
* WININET_Release */
INTERNET_SendCallback(lpwh, lpwh->dwContext,
INTERNET_STATUS_HANDLE_CLOSING, &hInternet,
sizeof(HINTERNET));
if( lpwh->lpwhparent )
WININET_Release( lpwh->lpwhparent );
WININET_FreeHandle( hInternet );
WININET_Release( lpwh );
return TRUE;
}
/***********************************************************************
* ConvertUrlComponentValue (Internal)
*
* Helper function for InternetCrackUrlW
*
*/
static void ConvertUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen,
LPWSTR lpwszComponent, DWORD dwwComponentLen,
LPCSTR lpszStart, LPCWSTR lpwszStart)
{
TRACE("%p %ld %p %ld %p %p\n", lppszComponent, *dwComponentLen, lpwszComponent, dwwComponentLen, lpszStart, lpwszStart);
if (*dwComponentLen != 0)
{
DWORD nASCIILength=WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,NULL,0,NULL,NULL);
if (*lppszComponent == NULL)
{
int nASCIIOffset=WideCharToMultiByte(CP_ACP,0,lpwszStart,lpwszComponent-lpwszStart,NULL,0,NULL,NULL);
if (lpwszComponent)
*lppszComponent = (LPSTR)lpszStart+nASCIIOffset;
else
*lppszComponent = NULL;
*dwComponentLen = nASCIILength;
}
else
{
DWORD ncpylen = min((*dwComponentLen)-1, nASCIILength);
WideCharToMultiByte(CP_ACP,0,lpwszComponent,dwwComponentLen,*lppszComponent,ncpylen+1,NULL,NULL);
(*lppszComponent)[ncpylen]=0;
*dwComponentLen = ncpylen;
}
}
}
/***********************************************************************
* InternetCrackUrlA (WININET.@)
*
* Break up URL into its components
*
* TODO: Handle dwFlags
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,
LPURL_COMPONENTSA lpUrlComponents)
{
DWORD nLength;
URL_COMPONENTSW UCW;
WCHAR* lpwszUrl;
TRACE("(%s %lu %lx %p)\n", debugstr_a(lpszUrl), dwUrlLength, dwFlags, lpUrlComponents);
if(dwUrlLength<=0)
dwUrlLength=-1;
nLength=MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,NULL,0);
/* if dwUrlLength=-1 then nLength includes null but length to
InternetCrackUrlW should not include it */
if (dwUrlLength == -1) nLength--;
lpwszUrl=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR)*nLength);
MultiByteToWideChar(CP_ACP,0,lpszUrl,dwUrlLength,lpwszUrl,nLength);
memset(&UCW,0,sizeof(UCW));
if(lpUrlComponents->dwHostNameLength!=0)
UCW.dwHostNameLength= lpUrlComponents->dwHostNameLength;
if(lpUrlComponents->dwUserNameLength!=0)
UCW.dwUserNameLength=lpUrlComponents->dwUserNameLength;
if(lpUrlComponents->dwPasswordLength!=0)
UCW.dwPasswordLength=lpUrlComponents->dwPasswordLength;
if(lpUrlComponents->dwUrlPathLength!=0)
UCW.dwUrlPathLength=lpUrlComponents->dwUrlPathLength;
if(lpUrlComponents->dwSchemeLength!=0)
UCW.dwSchemeLength=lpUrlComponents->dwSchemeLength;
if(lpUrlComponents->dwExtraInfoLength!=0)
UCW.dwExtraInfoLength=lpUrlComponents->dwExtraInfoLength;
if(!InternetCrackUrlW(lpwszUrl,nLength,dwFlags,&UCW))
{
HeapFree(GetProcessHeap(), 0, lpwszUrl);
return FALSE;
}
ConvertUrlComponentValue(&lpUrlComponents->lpszHostName, &lpUrlComponents->dwHostNameLength,
UCW.lpszHostName, UCW.dwHostNameLength,
lpszUrl, lpwszUrl);
ConvertUrlComponentValue(&lpUrlComponents->lpszUserName, &lpUrlComponents->dwUserNameLength,
UCW.lpszUserName, UCW.dwUserNameLength,
lpszUrl, lpwszUrl);
ConvertUrlComponentValue(&lpUrlComponents->lpszPassword, &lpUrlComponents->dwPasswordLength,
UCW.lpszPassword, UCW.dwPasswordLength,
lpszUrl, lpwszUrl);
ConvertUrlComponentValue(&lpUrlComponents->lpszUrlPath, &lpUrlComponents->dwUrlPathLength,
UCW.lpszUrlPath, UCW.dwUrlPathLength,
lpszUrl, lpwszUrl);
ConvertUrlComponentValue(&lpUrlComponents->lpszScheme, &lpUrlComponents->dwSchemeLength,
UCW.lpszScheme, UCW.dwSchemeLength,
lpszUrl, lpwszUrl);
ConvertUrlComponentValue(&lpUrlComponents->lpszExtraInfo, &lpUrlComponents->dwExtraInfoLength,
UCW.lpszExtraInfo, UCW.dwExtraInfoLength,
lpszUrl, lpwszUrl);
lpUrlComponents->nScheme=UCW.nScheme;
lpUrlComponents->nPort=UCW.nPort;
HeapFree(GetProcessHeap(), 0, lpwszUrl);
TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", lpszUrl,
debugstr_an(lpUrlComponents->lpszScheme,lpUrlComponents->dwSchemeLength),
debugstr_an(lpUrlComponents->lpszHostName,lpUrlComponents->dwHostNameLength),
debugstr_an(lpUrlComponents->lpszUrlPath,lpUrlComponents->dwUrlPathLength),
debugstr_an(lpUrlComponents->lpszExtraInfo,lpUrlComponents->dwExtraInfoLength));
return TRUE;
}
static const WCHAR url_schemes[][7] =
{
{'f','t','p',0},
{'g','o','p','h','e','r',0},
{'h','t','t','p',0},
{'h','t','t','p','s',0},
{'f','i','l','e',0},
{'n','e','w','s',0},
{'m','a','i','l','t','o',0},
{'r','e','s',0},
};
/***********************************************************************
* GetInternetSchemeW (internal)
*
* Get scheme of url
*
* RETURNS
* scheme on success
* INTERNET_SCHEME_UNKNOWN on failure
*
*/
static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp)
{
int i;
TRACE("%s %ld\n",debugstr_wn(lpszScheme, nMaxCmp), nMaxCmp);
if(lpszScheme==NULL)
return INTERNET_SCHEME_UNKNOWN;
for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++)
if (!strncmpW(lpszScheme, url_schemes[i], nMaxCmp))
return INTERNET_SCHEME_FIRST + i;
return INTERNET_SCHEME_UNKNOWN;
}
/***********************************************************************
* SetUrlComponentValueW (Internal)
*
* Helper function for InternetCrackUrlW
*
* PARAMS
* lppszComponent [O] Holds the returned string
* dwComponentLen [I] Holds the size of lppszComponent
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -