diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 23:51:28 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 23:51:28 +0000 |
commit | 21f20c8940b8b9f06b04ff142716201a2530f0a3 (patch) | |
tree | d68fcccc003b0c7edb4ce7620f2270fb608d4022 /net/proxy/proxy_resolver_js_bindings.cc | |
parent | 13d54f79c040c2e6beeed94e096d1fcf2b0f7101 (diff) | |
download | chromium_src-21f20c8940b8b9f06b04ff142716201a2530f0a3.zip chromium_src-21f20c8940b8b9f06b04ff142716201a2530f0a3.tar.gz chromium_src-21f20c8940b8b9f06b04ff142716201a2530f0a3.tar.bz2 |
Add three of the six extensions to PAC that Internet Explorer supports.
The following descriptions were taken from <http://blogs.msdn.com/wndp/articles/IPV6_PAC_Extensions_v0_9.aspx>
----------------------------
* myIpAddressEx():
Returns a semi-colon delimited string containing all IP addresses for localhost (IPv6 and/or IPv4), or an empty string if unable to resolve localhost to an IP address.
* dnsResolveEx(host):
Returns semi-colon delimited string containing IPv6 and IPv4 addresses or an empty string if host is not resolvable.
* isResolvableEx():
Returns TRUE if the host is resolvable to a IPv4 or IPv6 address, FALSE otherwise.
----------------------------
These differ from the vanilla PAC functions in the following ways:
* myIpAddressEx() returns all the addrsses for localhost (including IPv6 ones), whereas myIpAddress() only returns the first IPv4 one.
* On failure, myIpAddress() returns "127.0.0.1" whereas on failure myIpAddressEx() returns empty string.
* dnsResolveEx() returns a list of addresses (including IPV6 ones), whereas dnsResolve() only returns the first IPv4 address.
* On failure, dnsResolve() returns |null|, whereas on failure dnsResolveEx() returns empty string.
BUG=25407
TEST=ProxyResolverV8Test.DNSResolutionFailure, ProxyResolverJSBindingsTest.RestrictAddressFamily, ProxyResolverJSBindingsTest.ExFunctionsReturnList
Review URL: http://codereview.chromium.org/333006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30127 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_resolver_js_bindings.cc')
-rw-r--r-- | net/proxy/proxy_resolver_js_bindings.cc | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/net/proxy/proxy_resolver_js_bindings.cc b/net/proxy/proxy_resolver_js_bindings.cc index f9ea5ae..077e5c6 100644 --- a/net/proxy/proxy_resolver_js_bindings.cc +++ b/net/proxy/proxy_resolver_js_bindings.cc @@ -2,6 +2,14 @@ // source code is governed by a BSD-style license that can be found in the // LICENSE file. +#include "build/build_config.h" + +#if defined(OS_WIN) +#include <ws2tcpip.h> +#else +#include <netdb.h> +#endif + #include "net/proxy/proxy_resolver_js_bindings.h" #include "base/compiler_specific.h" @@ -97,21 +105,24 @@ class DefaultJSBindings : public ProxyResolverJSBindings { } // Handler for "myIpAddress()". Returns empty string on failure. + // TODO(eroman): Perhaps enumerate the interfaces directly, using + // getifaddrs(). virtual std::string MyIpAddress() { // DnsResolve("") returns "", so no need to check for failure. return DnsResolve(GetHostName()); } + // Handler for "myIpAddressEx()". Returns empty string on failure. + virtual std::string MyIpAddressEx() { + return DnsResolveEx(GetHostName()); + } + // Handler for "dnsResolve(host)". Returns empty string on failure. virtual std::string DnsResolve(const std::string& host) { - // TODO(eroman): Should this return our IP address, or fail, or - // simply be unspecified (works differently on windows and mac os x). - if (host.empty()) - return std::string(); - // Do a sync resolve of the hostname. - // Disable IPv6 results. We do this because Internet Explorer does it -- - // consequently a lot of existing PAC scripts assume they will only get + // Disable IPv6 results. We do this because the PAC specification isn't + // really IPv6 friendly, and Internet Explorer also restricts to IPv4. + // Consequently a lot of existing PAC scripts assume they will only get // IPv4 results, and will misbehave if they get an IPv6 result. // See http://crbug.com/24641 for more details. net::AddressList address_list; @@ -130,6 +141,31 @@ class DefaultJSBindings : public ProxyResolverJSBindings { return net::NetAddressToString(address_list.head()); } + // Handler for "dnsResolveEx(host)". Returns empty string on failure. + virtual std::string DnsResolveEx(const std::string& host) { + // Do a sync resolve of the hostname. + net::AddressList address_list; + int result = host_resolver_->Resolve(host, + ADDRESS_FAMILY_UNSPECIFIED, + &address_list); + + if (result != OK) + return std::string(); // Failed. + + // Stringify all of the addresses in the address list, separated + // by semicolons. + std::string address_list_str; + const struct addrinfo* current_address = address_list.head(); + while (current_address) { + if (!address_list_str.empty()) + address_list_str += ";"; + address_list_str += net::NetAddressToString(current_address); + current_address = current_address->ai_next; + } + + return address_list_str; + } + // Handler for when an error is encountered. |line_number| may be -1. virtual void OnError(int line_number, const std::string& message) { if (line_number == -1) |