1 // 2 // Copyright (C) 2011 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef SHILL_RESOLVER_H_ 18 #define SHILL_RESOLVER_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include <base/files/file_path.h> 24 #include <base/lazy_instance.h> 25 #include <base/memory/ref_counted.h> 26 27 #include "shill/refptr_types.h" 28 29 namespace shill { 30 31 // This provides a static function for dumping the DNS information out 32 // of an ipconfig into a "resolv.conf" formatted file. 33 class Resolver { 34 public: 35 // The default comma-separated list of search-list prefixes that 36 // should be ignored when writing out a DNS configuration. These 37 // are usually preconfigured by a DHCP server and are not of real 38 // value to the user. This will release DNS bandwidth for searches 39 // we expect will have a better chance of getting what the user is 40 // looking for. 41 static const char kDefaultIgnoredSearchList[]; 42 43 virtual ~Resolver(); 44 45 // Since this is a singleton, use Resolver::GetInstance()->Foo(). 46 static Resolver* GetInstance(); 47 set_path(const base::FilePath & path)48 virtual void set_path(const base::FilePath& path) { path_ = path; } 49 50 // Install domain name service parameters, given a list of 51 // DNS servers in |dns_servers|, and a list of DNS search suffixes in 52 // |domain_search|. 53 virtual bool SetDNSFromLists(const std::vector<std::string>& dns_servers, 54 const std::vector<std::string>& domain_search); 55 56 // Remove any created domain name service file. 57 virtual bool ClearDNS(); 58 59 // Sets the list of ignored DNS search suffixes. This list will be used 60 // to filter the domain_search parameter of later SetDNSFromLists() calls. set_ignored_search_list(const std::vector<std::string> & ignored_list)61 virtual void set_ignored_search_list( 62 const std::vector<std::string>& ignored_list) { 63 ignored_search_list_ = ignored_list; 64 } 65 66 protected: 67 Resolver(); 68 69 private: 70 friend struct base::DefaultLazyInstanceTraits<Resolver>; 71 friend class ResolverTest; 72 73 base::FilePath path_; 74 std::vector<std::string> ignored_search_list_; 75 76 DISALLOW_COPY_AND_ASSIGN(Resolver); 77 }; 78 79 } // namespace shill 80 81 #endif // SHILL_RESOLVER_H_ 82