📄 internet.c
字号:
* [O] Holds the length of the string in lppszComponent without '\0'
* lpszStart [I] Holds the string to copy from
* len [I] Holds the length of lpszStart without '\0'
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
static BOOL SetUrlComponentValueW(LPWSTR* lppszComponent, LPDWORD dwComponentLen, LPCWSTR lpszStart, DWORD len)
{
TRACE("%s (%ld)\n", debugstr_wn(lpszStart,len), len);
if ( (*dwComponentLen == 0) && (*lppszComponent == NULL) )
return FALSE;
if (*dwComponentLen != 0 || *lppszComponent == NULL)
{
if (*lppszComponent == NULL)
{
*lppszComponent = (LPWSTR)lpszStart;
*dwComponentLen = len;
}
else
{
DWORD ncpylen = min((*dwComponentLen)-1, len);
memcpy(*lppszComponent, lpszStart, ncpylen*sizeof(WCHAR));
(*lppszComponent)[ncpylen] = '\0';
*dwComponentLen = ncpylen;
}
}
return TRUE;
}
/***********************************************************************
* InternetCrackUrlW (WININET.@)
*/
BOOL WINAPI InternetCrackUrlW(LPCWSTR lpszUrl_orig, DWORD dwUrlLength_orig, DWORD dwFlags,
LPURL_COMPONENTSW lpUC)
{
/*
* RFC 1808
* <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
*
*/
LPCWSTR lpszParam = NULL;
BOOL bIsAbsolute = FALSE;
LPCWSTR lpszap, lpszUrl = lpszUrl_orig;
LPCWSTR lpszcp = NULL;
LPWSTR lpszUrl_decode = NULL;
DWORD dwUrlLength = dwUrlLength_orig;
const WCHAR lpszSeparators[3]={';','?',0};
const WCHAR lpszSlash[2]={'/',0};
if(dwUrlLength==0)
dwUrlLength=strlenW(lpszUrl);
TRACE("(%s %lu %lx %p)\n", debugstr_w(lpszUrl), dwUrlLength, dwFlags, lpUC);
if (dwFlags & ICU_DECODE)
{
lpszUrl_decode=HeapAlloc( GetProcessHeap(), 0, dwUrlLength * sizeof (WCHAR) );
if( InternetCanonicalizeUrlW(lpszUrl_orig, lpszUrl_decode, &dwUrlLength, dwFlags))
{
lpszUrl = lpszUrl_decode;
}
}
lpszap = lpszUrl;
/* Determine if the URI is absolute. */
while (*lpszap != '\0')
{
if (isalnumW(*lpszap))
{
lpszap++;
continue;
}
if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))
{
bIsAbsolute = TRUE;
lpszcp = lpszap;
}
else
{
lpszcp = lpszUrl; /* Relative url */
}
break;
}
lpUC->nScheme = INTERNET_SCHEME_UNKNOWN;
lpUC->nPort = INTERNET_INVALID_PORT_NUMBER;
/* Parse <params> */
lpszParam = strpbrkW(lpszap, lpszSeparators);
SetUrlComponentValueW(&lpUC->lpszExtraInfo, &lpUC->dwExtraInfoLength,
lpszParam, lpszParam ? dwUrlLength-(lpszParam-lpszUrl) : 0);
if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */
{
LPCWSTR lpszNetLoc;
/* Get scheme first. */
lpUC->nScheme = GetInternetSchemeW(lpszUrl, lpszcp - lpszUrl);
SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength,
lpszUrl, lpszcp - lpszUrl);
/* Eat ':' in protocol. */
lpszcp++;
/* double slash indicates the net_loc portion is present */
if ((lpszcp[0] == '/') && (lpszcp[1] == '/'))
{
lpszcp += 2;
lpszNetLoc = strpbrkW(lpszcp, lpszSlash);
if (lpszParam)
{
if (lpszNetLoc)
lpszNetLoc = min(lpszNetLoc, lpszParam);
else
lpszNetLoc = lpszParam;
}
else if (!lpszNetLoc)
lpszNetLoc = lpszcp + dwUrlLength-(lpszcp-lpszUrl);
/* Parse net-loc */
if (lpszNetLoc)
{
LPCWSTR lpszHost;
LPCWSTR lpszPort;
/* [<user>[<:password>]@]<host>[:<port>] */
/* First find the user and password if they exist */
lpszHost = strchrW(lpszcp, '@');
if (lpszHost == NULL || lpszHost > lpszNetLoc)
{
/* username and password not specified. */
SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
}
else /* Parse out username and password */
{
LPCWSTR lpszUser = lpszcp;
LPCWSTR lpszPasswd = lpszHost;
while (lpszcp < lpszHost)
{
if (*lpszcp == ':')
lpszPasswd = lpszcp;
lpszcp++;
}
SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength,
lpszUser, lpszPasswd - lpszUser);
if (lpszPasswd != lpszHost)
lpszPasswd++;
SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength,
lpszPasswd == lpszHost ? NULL : lpszPasswd,
lpszHost - lpszPasswd);
lpszcp++; /* Advance to beginning of host */
}
/* Parse <host><:port> */
lpszHost = lpszcp;
lpszPort = lpszNetLoc;
/* special case for res:// URLs: there is no port here, so the host is the
entire string up to the first '/' */
if(lpUC->nScheme==INTERNET_SCHEME_RES)
{
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
lpszHost, lpszPort - lpszHost);
lpszcp=lpszNetLoc;
}
else
{
while (lpszcp < lpszNetLoc)
{
if (*lpszcp == ':')
lpszPort = lpszcp;
lpszcp++;
}
/* If the scheme is "file" and the host is just one letter, it's not a host */
if(lpUC->nScheme==INTERNET_SCHEME_FILE && (lpszPort-lpszHost)==1)
{
lpszcp=lpszHost;
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
NULL, 0);
}
else
{
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength,
lpszHost, lpszPort - lpszHost);
if (lpszPort != lpszNetLoc)
lpUC->nPort = atoiW(++lpszPort);
else switch (lpUC->nScheme)
{
case INTERNET_SCHEME_HTTP:
lpUC->nPort = INTERNET_DEFAULT_HTTP_PORT;
break;
case INTERNET_SCHEME_HTTPS:
lpUC->nPort = INTERNET_DEFAULT_HTTPS_PORT;
break;
case INTERNET_SCHEME_FTP:
lpUC->nPort = INTERNET_DEFAULT_FTP_PORT;
break;
case INTERNET_SCHEME_GOPHER:
lpUC->nPort = INTERNET_DEFAULT_GOPHER_PORT;
break;
default:
break;
}
}
}
}
}
else
{
SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
}
}
else
{
SetUrlComponentValueW(&lpUC->lpszScheme, &lpUC->dwSchemeLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszUserName, &lpUC->dwUserNameLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszPassword, &lpUC->dwPasswordLength, NULL, 0);
SetUrlComponentValueW(&lpUC->lpszHostName, &lpUC->dwHostNameLength, NULL, 0);
}
/* Here lpszcp points to:
*
* <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))
{
INT len;
/* Only truncate the parameter list if it's already been saved
* in lpUC->lpszExtraInfo.
*/
if (lpszParam && lpUC->dwExtraInfoLength && lpUC->lpszExtraInfo)
len = lpszParam - lpszcp;
else
{
/* Leave the parameter list in lpszUrlPath. Strip off any trailing
* newlines if necessary.
*/
LPWSTR lpsznewline = strchrW(lpszcp, '\n');
if (lpsznewline != NULL)
len = lpsznewline - lpszcp;
else
len = dwUrlLength-(lpszcp-lpszUrl);
}
SetUrlComponentValueW(&lpUC->lpszUrlPath, &lpUC->dwUrlPathLength,
lpszcp, len);
}
else
{
lpUC->dwUrlPathLength = 0;
}
TRACE("%s: scheme(%s) host(%s) path(%s) extra(%s)\n", debugstr_wn(lpszUrl,dwUrlLength),
debugstr_wn(lpUC->lpszScheme,lpUC->dwSchemeLength),
debugstr_wn(lpUC->lpszHostName,lpUC->dwHostNameLength),
debugstr_wn(lpUC->lpszUrlPath,lpUC->dwUrlPathLength),
debugstr_wn(lpUC->lpszExtraInfo,lpUC->dwExtraInfoLength));
if (lpszUrl_decode)
HeapFree(GetProcessHeap(), 0, lpszUrl_decode );
return TRUE;
}
/***********************************************************************
* InternetAttemptConnect (WININET.@)
*
* Attempt to make a connection to the internet
*
* RETURNS
* ERROR_SUCCESS on success
* Error value on failure
*
*/
DWORD WINAPI InternetAttemptConnect(DWORD dwReserved)
{
FIXME("Stub\n");
return ERROR_SUCCESS;
}
/***********************************************************************
* InternetCanonicalizeUrlA (WININET.@)
*
* Escape unsafe characters and spaces
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetCanonicalizeUrlA(LPCSTR lpszUrl, LPSTR lpszBuffer,
LPDWORD lpdwBufferLength, DWORD dwFlags)
{
HRESULT hr;
DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
if(dwFlags & ICU_DECODE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_DECODE;
}
if(dwFlags & ICU_ESCAPE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_ESCAPE;
}
if(dwFlags & ICU_BROWSER_MODE)
{
dwURLFlags |= URL_BROWSER_MODE;
dwFlags &= ~ICU_BROWSER_MODE;
}
if(dwFlags)
FIXME("Unhandled flags 0x%08lx\n", dwFlags);
TRACE("%s %p %p %08lx\n", debugstr_a(lpszUrl), lpszBuffer,
lpdwBufferLength, dwURLFlags);
/* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
dwFlags ^= ICU_NO_ENCODE;
hr = UrlCanonicalizeA(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
return (hr == S_OK) ? TRUE : FALSE;
}
/***********************************************************************
* InternetCanonicalizeUrlW (WININET.@)
*
* Escape unsafe characters and spaces
*
* RETURNS
* TRUE on success
* FALSE on failure
*
*/
BOOL WINAPI InternetCanonicalizeUrlW(LPCWSTR lpszUrl, LPWSTR lpszBuffer,
LPDWORD lpdwBufferLength, DWORD dwFlags)
{
HRESULT hr;
DWORD dwURLFlags= 0x80000000; /* Don't know what this means */
if(dwFlags & ICU_DECODE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_DECODE;
}
if(dwFlags & ICU_ESCAPE)
{
dwURLFlags |= URL_UNESCAPE;
dwFlags &= ~ICU_ESCAPE;
}
if(dwFlags & ICU_BROWSER_MODE)
{
dwURLFlags |= URL_BROWSER_MODE;
dwFlags &= ~ICU_BROWSER_MODE;
}
if(dwFlags)
FIXME("Unhandled flags 0x%08lx\n", dwFlags);
TRACE("%s %p %p %08lx\n", debugstr_w(lpszUrl), lpszBuffer,
lpdwBufferLength, dwURLFlags);
/* Flip this bit to correspond to URL_ESCAPE_UNSAFE */
dwFlags ^= ICU_NO_ENCODE;
hr = UrlCanonicalizeW(lpszUrl, lpszBuffer, lpdwBufferLength, dwURLFlags);
return (hr == S_OK) ? TRUE : FALSE;
}
/***********************************************************************
* InternetSetStatusCallbackA (WININET.@)
*
* Sets up a callback function which is called as progress is made
* during an operation.
*
* RETURNS
* Previous callback or NULL on success
* INTERNET_INVALID_STATUS_CALLBACK on failure
*
*/
INTERNET_STATUS_CALLBACK WINAPI InternetSetStatusCallbackA(
HINTERNET hInternet ,INTERNET_STATUS_CALLBACK lpfnIntCB)
{
INTERNET_STATUS_CALLBACK retVal;
LPWININETHANDLEHEADER lpwh;
TRACE("0x%08lx\n", (ULONG)hInternet);
lpwh = WININET_GetObject(hInternet);
if (!lpwh)
return INTERNET_INVALID_STATUS_CALLBACK;
lpwh->dwInternalFlags &= ~INET_CALLBACKW;
retVal = lpwh->lpfnStatusCB;
lpwh->lpfnStatusCB = lpfnIntCB;
WININET_Release( lpwh );
return retVal;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -