Commit f79c5917 authored by droger@chromium.org's avatar droger@chromium.org

Remove private system API calls in dns_config_service_posix on iOS

BUG=335000

Review URL: https://codereview.chromium.org/135043003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245391 0039d316-1c4b-4281-b951-d872f2087c98
parent 1e4fdc0b
...@@ -21,68 +21,9 @@ ...@@ -21,68 +21,9 @@
#include "net/dns/notify_watcher_mac.h" #include "net/dns/notify_watcher_mac.h"
#include "net/dns/serial_worker.h" #include "net/dns/serial_worker.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX) && !defined(OS_IOS)
#include <dlfcn.h> #include "net/dns/dns_config_watcher_mac.h"
#endif
#include "third_party/apple_apsl/dnsinfo.h"
namespace {
// dnsinfo symbols are available via libSystem.dylib, but can also be present in
// SystemConfiguration.framework. To avoid confusion, load them explicitly from
// libSystem.dylib.
class DnsInfoApi {
public:
typedef const char* (*dns_configuration_notify_key_t)();
typedef dns_config_t* (*dns_configuration_copy_t)();
typedef void (*dns_configuration_free_t)(dns_config_t*);
DnsInfoApi()
: dns_configuration_notify_key(NULL),
dns_configuration_copy(NULL),
dns_configuration_free(NULL) {
handle_ = dlopen("/usr/lib/libSystem.dylib",
RTLD_LAZY | RTLD_NOLOAD);
if (!handle_)
return;
dns_configuration_notify_key =
reinterpret_cast<dns_configuration_notify_key_t>(
dlsym(handle_, "dns_configuration_notify_key"));
dns_configuration_copy =
reinterpret_cast<dns_configuration_copy_t>(
dlsym(handle_, "dns_configuration_copy"));
dns_configuration_free =
reinterpret_cast<dns_configuration_free_t>(
dlsym(handle_, "dns_configuration_free"));
}
~DnsInfoApi() {
if (handle_)
dlclose(handle_);
}
dns_configuration_notify_key_t dns_configuration_notify_key;
dns_configuration_copy_t dns_configuration_copy;
dns_configuration_free_t dns_configuration_free;
private:
void* handle_;
};
const DnsInfoApi& GetDnsInfoApi() {
static base::LazyInstance<DnsInfoApi>::Leaky api = LAZY_INSTANCE_INITIALIZER;
return api.Get();
}
struct DnsConfigTDeleter {
inline void operator()(dns_config_t* ptr) const {
if (GetDnsInfoApi().dns_configuration_free)
GetDnsInfoApi().dns_configuration_free(ptr);
}
};
} // namespace
#endif // defined(OS_MACOSX)
namespace net { namespace net {
...@@ -94,20 +35,20 @@ namespace { ...@@ -94,20 +35,20 @@ namespace {
const base::FilePath::CharType* kFilePathHosts = const base::FilePath::CharType* kFilePathHosts =
FILE_PATH_LITERAL("/etc/hosts"); FILE_PATH_LITERAL("/etc/hosts");
#if defined(OS_MACOSX) #if defined(OS_IOS)
class ConfigWatcher {
// There is no plublic API to watch the DNS configuration on iOS.
class DnsConfigWatcher {
public: public:
bool Watch(const base::Callback<void(bool succeeded)>& callback) { typedef base::Callback<void(bool succeeded)> CallbackType;
if (!GetDnsInfoApi().dns_configuration_notify_key)
return false;
return watcher_.Watch(GetDnsInfoApi().dns_configuration_notify_key(),
callback);
}
private: bool Watch(const CallbackType& callback) {
NotifyWatcherMac watcher_; return false;
}
}; };
#else
#elif !defined(OS_MACOSX)
// DnsConfigWatcher for OS_MACOSX is in dns_config_watcher_mac.{hh,cc}.
#ifndef _PATH_RESCONF // Normally defined in <resolv.h> #ifndef _PATH_RESCONF // Normally defined in <resolv.h>
#define _PATH_RESCONF "/etc/resolv.conf" #define _PATH_RESCONF "/etc/resolv.conf"
...@@ -116,14 +57,14 @@ class ConfigWatcher { ...@@ -116,14 +57,14 @@ class ConfigWatcher {
static const base::FilePath::CharType* kFilePathConfig = static const base::FilePath::CharType* kFilePathConfig =
FILE_PATH_LITERAL(_PATH_RESCONF); FILE_PATH_LITERAL(_PATH_RESCONF);
class ConfigWatcher { class DnsConfigWatcher {
public: public:
typedef base::Callback<void(bool succeeded)> CallbackType; typedef base::Callback<void(bool succeeded)> CallbackType;
bool Watch(const CallbackType& callback) { bool Watch(const CallbackType& callback) {
callback_ = callback; callback_ = callback;
return watcher_.Watch(base::FilePath(kFilePathConfig), false, return watcher_.Watch(base::FilePath(kFilePathConfig), false,
base::Bind(&ConfigWatcher::OnCallback, base::Bind(&DnsConfigWatcher::OnCallback,
base::Unretained(this))); base::Unretained(this)));
} }
...@@ -165,31 +106,18 @@ ConfigParsePosixResult ReadDnsConfig(DnsConfig* config) { ...@@ -165,31 +106,18 @@ ConfigParsePosixResult ReadDnsConfig(DnsConfig* config) {
#endif #endif
#endif #endif
#if defined(OS_MACOSX) #if defined(OS_MACOSX) && !defined(OS_IOS)
if (!GetDnsInfoApi().dns_configuration_copy) ConfigParsePosixResult error = DnsConfigWatcher::CheckDnsConfig();
return CONFIG_PARSE_POSIX_NO_DNSINFO; switch (error) {
scoped_ptr<dns_config_t, DnsConfigTDeleter> dns_config( case CONFIG_PARSE_POSIX_OK:
GetDnsInfoApi().dns_configuration_copy()); break;
if (!dns_config) case CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS:
return CONFIG_PARSE_POSIX_NO_DNSINFO; LOG(WARNING) << "dns_config has unhandled options!";
config->unhandled_options = true;
// TODO(szym): Parse dns_config_t for resolvers rather than res_state. default:
// DnsClient can't handle domain-specific unscoped resolvers. return error;
unsigned num_resolvers = 0;
for (int i = 0; i < dns_config->n_resolver; ++i) {
dns_resolver_t* resolver = dns_config->resolver[i];
if (!resolver->n_nameserver)
continue;
if (resolver->options && !strcmp(resolver->options, "mdns"))
continue;
++num_resolvers;
}
if (num_resolvers > 1) {
LOG(WARNING) << "dns_config has unhandled options!";
config->unhandled_options = true;
return CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS;
} }
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX) && !defined(OS_IOS)
// Override timeout value to match default setting on Windows. // Override timeout value to match default setting on Windows.
config->timeout = base::TimeDelta::FromSeconds(kDnsTimeoutSeconds); config->timeout = base::TimeDelta::FromSeconds(kDnsTimeoutSeconds);
return result; return result;
...@@ -246,7 +174,7 @@ class DnsConfigServicePosix::Watcher { ...@@ -246,7 +174,7 @@ class DnsConfigServicePosix::Watcher {
base::WeakPtrFactory<Watcher> weak_factory_; base::WeakPtrFactory<Watcher> weak_factory_;
DnsConfigServicePosix* service_; DnsConfigServicePosix* service_;
ConfigWatcher config_watcher_; DnsConfigWatcher config_watcher_;
base::FilePathWatcher hosts_watcher_; base::FilePathWatcher hosts_watcher_;
DISALLOW_COPY_AND_ASSIGN(Watcher); DISALLOW_COPY_AND_ASSIGN(Watcher);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/dns/dns_config_watcher_mac.h"
#include <dlfcn.h>
#include "base/lazy_instance.h"
#include "third_party/apple_apsl/dnsinfo.h"
namespace {
// dnsinfo symbols are available via libSystem.dylib, but can also be present in
// SystemConfiguration.framework. To avoid confusion, load them explicitly from
// libSystem.dylib.
class DnsInfoApi {
public:
typedef const char* (*dns_configuration_notify_key_t)();
typedef dns_config_t* (*dns_configuration_copy_t)();
typedef void (*dns_configuration_free_t)(dns_config_t*);
DnsInfoApi()
: dns_configuration_notify_key(NULL),
dns_configuration_copy(NULL),
dns_configuration_free(NULL) {
handle_ = dlopen("/usr/lib/libSystem.dylib",
RTLD_LAZY | RTLD_NOLOAD);
if (!handle_)
return;
dns_configuration_notify_key =
reinterpret_cast<dns_configuration_notify_key_t>(
dlsym(handle_, "dns_configuration_notify_key"));
dns_configuration_copy =
reinterpret_cast<dns_configuration_copy_t>(
dlsym(handle_, "dns_configuration_copy"));
dns_configuration_free =
reinterpret_cast<dns_configuration_free_t>(
dlsym(handle_, "dns_configuration_free"));
}
~DnsInfoApi() {
if (handle_)
dlclose(handle_);
}
dns_configuration_notify_key_t dns_configuration_notify_key;
dns_configuration_copy_t dns_configuration_copy;
dns_configuration_free_t dns_configuration_free;
private:
void* handle_;
};
const DnsInfoApi& GetDnsInfoApi() {
static base::LazyInstance<DnsInfoApi>::Leaky api = LAZY_INSTANCE_INITIALIZER;
return api.Get();
}
struct DnsConfigTDeleter {
inline void operator()(dns_config_t* ptr) const {
if (GetDnsInfoApi().dns_configuration_free)
GetDnsInfoApi().dns_configuration_free(ptr);
}
};
} // namespace
namespace net {
namespace internal {
bool DnsConfigWatcher::Watch(
const base::Callback<void(bool succeeded)>& callback) {
if (!GetDnsInfoApi().dns_configuration_notify_key)
return false;
return watcher_.Watch(GetDnsInfoApi().dns_configuration_notify_key(),
callback);
}
// static
ConfigParsePosixResult DnsConfigWatcher::CheckDnsConfig() {
if (!GetDnsInfoApi().dns_configuration_copy)
return CONFIG_PARSE_POSIX_NO_DNSINFO;
scoped_ptr<dns_config_t, DnsConfigTDeleter> dns_config(
GetDnsInfoApi().dns_configuration_copy());
if (!dns_config)
return CONFIG_PARSE_POSIX_NO_DNSINFO;
// TODO(szym): Parse dns_config_t for resolvers rather than res_state.
// DnsClient can't handle domain-specific unscoped resolvers.
unsigned num_resolvers = 0;
for (int i = 0; i < dns_config->n_resolver; ++i) {
dns_resolver_t* resolver = dns_config->resolver[i];
if (!resolver->n_nameserver)
continue;
if (resolver->options && !strcmp(resolver->options, "mdns"))
continue;
++num_resolvers;
}
if (num_resolvers > 1)
return CONFIG_PARSE_POSIX_UNHANDLED_OPTIONS;
return CONFIG_PARSE_POSIX_OK;
}
} // naespace internal
} // namespace net
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/callback_forward.h"
#include "net/dns/dns_config_service_posix.h"
#include "net/dns/notify_watcher_mac.h"
namespace net {
namespace internal {
// Watches DNS configuration on Mac.
class DnsConfigWatcher {
public:
bool Watch(const base::Callback<void(bool succeeded)>& callback);
// Returns an error if the DNS configuration is invalid.
// Returns CONFIG_PARSE_POSIX_OK otherwise.
static ConfigParsePosixResult CheckDnsConfig();
private:
NotifyWatcherMac watcher_;
};
} // naespace internal
} // namespace net
...@@ -474,6 +474,8 @@ ...@@ -474,6 +474,8 @@
'dns/dns_config_service_posix.h', 'dns/dns_config_service_posix.h',
'dns/dns_config_service_win.cc', 'dns/dns_config_service_win.cc',
'dns/dns_config_service_win.h', 'dns/dns_config_service_win.h',
'dns/dns_config_watcher_mac.cc',
'dns/dns_config_watcher_mac.h',
'dns/dns_hosts.cc', 'dns/dns_hosts.cc',
'dns/dns_hosts.h', 'dns/dns_hosts.h',
'dns/dns_protocol.h', 'dns/dns_protocol.h',
...@@ -1579,7 +1581,6 @@ ...@@ -1579,7 +1581,6 @@
['include', '^cert/test_root_certs_nss\\.cc$'], ['include', '^cert/test_root_certs_nss\\.cc$'],
['include', '^cert/x509_util_nss\\.cc$'], ['include', '^cert/x509_util_nss\\.cc$'],
['include', '^cert/x509_util_nss\\.h$'], ['include', '^cert/x509_util_nss\\.h$'],
['include', '^dns/notify_watcher_mac\\.cc$'],
['include', '^proxy/proxy_resolver_mac\\.cc$'], ['include', '^proxy/proxy_resolver_mac\\.cc$'],
['include', '^proxy/proxy_server_mac\\.cc$'], ['include', '^proxy/proxy_server_mac\\.cc$'],
['include', '^ocsp/nss_ocsp\\.cc$'], ['include', '^ocsp/nss_ocsp\\.cc$'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment