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:
Johann Hofmann 2017-03-31 22:39:45 +02:00
Родитель cd1cbcef0f
Коммит 023ccb065e
2 изменённых файлов: 37 добавлений и 0 удалений

Просмотреть файл

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