mukesh agrawal | 23ac6b7 | 2013-01-31 18:52:37 -0800 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_RESOLVER_ |
| 6 | #define SHILL_RESOLVER_ |
| 7 | |
Hristo Stefanov | ed2c28c | 2011-11-29 15:37:30 -0800 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 11 | #include <base/file_path.h> |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 12 | #include <base/lazy_instance.h> |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 13 | #include <base/memory/ref_counted.h> |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 14 | |
| 15 | #include "shill/refptr_types.h" |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | // This provides a static function for dumping the DNS information out |
| 20 | // of an ipconfig into a "resolv.conf" formatted file. |
| 21 | class Resolver { |
| 22 | public: |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 23 | // The default comma-separated list of search-list prefixes that |
| 24 | // should be ignored when writing out a DNS configuration. These |
| 25 | // are usually preconfigured by a DHCP server and are not of real |
| 26 | // value to the user. This will release DNS bandwidth for searches |
| 27 | // we expect will have a better chance of getting what the user is |
| 28 | // looking for. |
| 29 | static const char kDefaultIgnoredSearchList[]; |
| 30 | |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 31 | virtual ~Resolver(); |
| 32 | |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 33 | // Since this is a singleton, use Resolver::GetInstance()->Foo() |
| 34 | static Resolver *GetInstance(); |
| 35 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 36 | virtual void set_path(const base::FilePath &path) { path_ = path; } |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 37 | |
Paul Stewart | 6f65c0b | 2012-09-11 14:57:32 -0700 | [diff] [blame] | 38 | // Install domain name service parameters, given a list of |
mukesh agrawal | 23ac6b7 | 2013-01-31 18:52:37 -0800 | [diff] [blame] | 39 | // DNS servers in |dns_servers|, and a list of DNS search suffixes in |
| 40 | // |domain_search|. |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 41 | virtual bool SetDNSFromLists(const std::vector<std::string> &dns_servers, |
mukesh agrawal | 23ac6b7 | 2013-01-31 18:52:37 -0800 | [diff] [blame] | 42 | const std::vector<std::string> &domain_search); |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 43 | |
Paul Stewart | bf66761 | 2012-06-29 14:49:54 -0700 | [diff] [blame] | 44 | // Remove any created domain name service file. |
Paul Stewart | dd60e45 | 2011-08-08 11:38:36 -0700 | [diff] [blame] | 45 | virtual bool ClearDNS(); |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 46 | |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 47 | // Sets the list of ignored DNS search suffixes. This list will be used |
| 48 | // to filter the domain_search parameter of later SetDNSFromLists() calls. |
| 49 | virtual void set_ignored_search_list( |
| 50 | const std::vector<std::string> &ignored_list) { |
| 51 | ignored_search_list_ = ignored_list; |
| 52 | } |
| 53 | |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 54 | protected: |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 55 | Resolver(); |
Paul Stewart | 0d2ada3 | 2011-08-09 17:01:57 -0700 | [diff] [blame] | 56 | |
| 57 | private: |
| 58 | friend struct base::DefaultLazyInstanceTraits<Resolver>; |
| 59 | friend class ResolverTest; |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 60 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 61 | base::FilePath path_; |
Paul Stewart | 4d5efb7 | 2012-09-17 12:24:34 -0700 | [diff] [blame] | 62 | std::vector<std::string> ignored_search_list_; |
Paul Stewart | b606394 | 2011-08-05 10:17:29 -0700 | [diff] [blame] | 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(Resolver); |
| 65 | }; |
| 66 | |
| 67 | } // namespace shill |
| 68 | |
| 69 | #endif // SHILL_RESOLVER_ |