OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/dns_config_service_posix.h" | 5 #include "net/dns/dns_config_service_posix.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // A SerialWorker that uses ResolverLib to initialize res_state and converts | 24 // A SerialWorker that uses ResolverLib to initialize res_state and converts |
25 // it to DnsConfig. | 25 // it to DnsConfig. |
26 class DnsConfigServicePosix::ConfigReader : public SerialWorker { | 26 class DnsConfigServicePosix::ConfigReader : public SerialWorker { |
27 public: | 27 public: |
28 explicit ConfigReader(DnsConfigServicePosix* service) | 28 explicit ConfigReader(DnsConfigServicePosix* service) |
29 : service_(service), | 29 : service_(service), |
30 success_(false) {} | 30 success_(false) {} |
31 | 31 |
32 void DoWork() OVERRIDE { | 32 void DoWork() OVERRIDE { |
| 33 success_ = false; |
| 34 #if defined(OS_ANDROID) |
| 35 NOTIMPLEMENTED(); |
| 36 #else |
33 #if defined(OS_OPENBSD) | 37 #if defined(OS_OPENBSD) |
| 38 // Note: res_ninit in glibc always returns 0 and sets RES_INIT. |
| 39 // res_init behaves the same way. |
34 if ((res_init() == 0) && (_res.options & RES_INIT)) { | 40 if ((res_init() == 0) && (_res.options & RES_INIT)) { |
35 success_ = ConvertResToConfig(_res, &dns_config_); | 41 success_ = ConvertResToConfig(_res, &dns_config_); |
| 42 } |
36 #else | 43 #else |
37 struct __res_state res; | 44 struct __res_state res; |
38 if ((res_ninit(&res) == 0) && (res.options & RES_INIT)) { | 45 if ((res_ninit(&res) == 0) && (res.options & RES_INIT)) { |
39 success_ = ConvertResToConfig(res, &dns_config_); | 46 success_ = ConvertResToConfig(res, &dns_config_); |
| 47 } |
40 #endif | 48 #endif |
41 } else { | |
42 // Note: res_ninit in glibc always returns 0 and sets RES_INIT. | |
43 // res_init behaves the same way. | |
44 success_ = false; | |
45 } | |
46 #if defined(OS_MACOSX) | 49 #if defined(OS_MACOSX) |
47 res_ndestroy(&res); | 50 res_ndestroy(&res); |
48 #elif !defined(OS_OPENBSD) | 51 #elif !defined(OS_OPENBSD) |
49 res_nclose(&res); | 52 res_nclose(&res); |
50 #endif | 53 #endif |
| 54 #endif // defined(OS_ANDROID) |
51 } | 55 } |
52 | 56 |
53 void OnWorkFinished() OVERRIDE { | 57 void OnWorkFinished() OVERRIDE { |
54 DCHECK(!IsCancelled()); | 58 DCHECK(!IsCancelled()); |
55 if (success_) | 59 if (success_) |
56 service_->OnConfigRead(dns_config_); | 60 service_->OnConfigRead(dns_config_); |
57 } | 61 } |
58 | 62 |
59 private: | 63 private: |
60 virtual ~ConfigReader() {} | 64 virtual ~ConfigReader() {} |
(...skipping 16 matching lines...) Expand all Loading... |
77 new ConfigReader(this)); | 81 new ConfigReader(this)); |
78 FilePath hosts_path(FILE_PATH_LITERAL("/etc/hosts")); | 82 FilePath hosts_path(FILE_PATH_LITERAL("/etc/hosts")); |
79 hosts_watcher_->StartWatch(hosts_path, new DnsHostsReader(hosts_path, this)); | 83 hosts_watcher_->StartWatch(hosts_path, new DnsHostsReader(hosts_path, this)); |
80 } | 84 } |
81 | 85 |
82 // static | 86 // static |
83 DnsConfigService* DnsConfigService::CreateSystemService() { | 87 DnsConfigService* DnsConfigService::CreateSystemService() { |
84 return new DnsConfigServicePosix(); | 88 return new DnsConfigServicePosix(); |
85 } | 89 } |
86 | 90 |
| 91 #if !defined(OS_ANDROID) |
87 bool ConvertResToConfig(const struct __res_state& res, DnsConfig* dns_config) { | 92 bool ConvertResToConfig(const struct __res_state& res, DnsConfig* dns_config) { |
88 CHECK(dns_config != NULL); | 93 CHECK(dns_config != NULL); |
89 DCHECK(res.options & RES_INIT); | 94 DCHECK(res.options & RES_INIT); |
90 | 95 |
91 dns_config->nameservers.clear(); | 96 dns_config->nameservers.clear(); |
92 | 97 |
93 #if defined(OS_LINUX) | 98 #if defined(OS_LINUX) |
94 // Initially, glibc stores IPv6 in _ext.nsaddrs and IPv4 in nsaddr_list. | 99 // Initially, glibc stores IPv6 in _ext.nsaddrs and IPv4 in nsaddr_list. |
95 // Next (res_send.c::__libc_res_nsend), it copies nsaddr_list after nsaddrs. | 100 // Next (res_send.c::__libc_res_nsend), it copies nsaddr_list after nsaddrs. |
96 // If RES_ROTATE is enabled, the list is shifted left after each res_send. | 101 // If RES_ROTATE is enabled, the list is shifted left after each res_send. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 dns_config->ndots = res.ndots; | 134 dns_config->ndots = res.ndots; |
130 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); | 135 dns_config->timeout = base::TimeDelta::FromSeconds(res.retrans); |
131 dns_config->attempts = res.retry; | 136 dns_config->attempts = res.retry; |
132 #if defined(RES_ROTATE) | 137 #if defined(RES_ROTATE) |
133 dns_config->rotate = res.options & RES_ROTATE; | 138 dns_config->rotate = res.options & RES_ROTATE; |
134 #endif | 139 #endif |
135 dns_config->edns0 = res.options & RES_USE_EDNS0; | 140 dns_config->edns0 = res.options & RES_USE_EDNS0; |
136 | 141 |
137 return true; | 142 return true; |
138 } | 143 } |
| 144 #endif // !defined(OS_ANDROID) |
139 | 145 |
140 } // namespace net | 146 } // namespace net |
OLD | NEW |