зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1337246 - Part 1 - Add a hostnameIsLocalIPAddress function to nsIIOService. r=valentin
MozReview-Commit-ID: 81A37b1juGD --HG-- extra : rebase_source : 081b160d2822487a2e3b4e05ba34d614f0ad5042
This commit is contained in:
Родитель
cd1cbcef0f
Коммит
023ccb065e
|
@ -176,6 +176,14 @@ interface nsIIOService : nsISupports
|
|||
* @throws NS_ERROR_MALFORMED_URI if URL string is not of the right form.
|
||||
*/
|
||||
ACString extractScheme(in AUTF8String urlString);
|
||||
|
||||
/**
|
||||
* Checks if a URI host is a local IPv4 or IPv6 address literal.
|
||||
*
|
||||
* @param nsIURI the URI that contains the hostname to check
|
||||
* @return true if the URI hostname is a local IP address
|
||||
*/
|
||||
boolean hostnameIsLocalIPAddress(in nsIURI aURI);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -585,6 +585,35 @@ nsIOService::ExtractScheme(const nsACString &inURI, nsACString &scheme)
|
|||
return net_ExtractURLScheme(inURI, scheme);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::HostnameIsLocalIPAddress(nsIURI *aURI, bool *aResult)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
|
||||
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
|
||||
NS_ENSURE_ARG_POINTER(innerURI);
|
||||
|
||||
nsAutoCString host;
|
||||
nsresult rv = innerURI->GetAsciiHost(host);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
*aResult = false;
|
||||
|
||||
PRNetAddr addr;
|
||||
PRStatus result = PR_StringToNetAddr(host.get(), &addr);
|
||||
if (result == PR_SUCCESS) {
|
||||
NetAddr netAddr;
|
||||
PRNetAddrToNetAddr(&addr, &netAddr);
|
||||
if (IsIPAddrLocal(&netAddr)) {
|
||||
*aResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetProtocolFlags(const char* scheme, uint32_t *flags)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче