• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dns_resolv_config.h"
17 
18 namespace OHOS::nmd {
DelayedTaskWrapper(std::string hostName,NetManagerStandard::LRUCache<AddrInfo> & cache)19 DnsResolvConfig::DelayedTaskWrapper::DelayedTaskWrapper(std::string hostName,
20                                                         NetManagerStandard::LRUCache<AddrInfo> &cache)
21     : hostName_(std::move(hostName)), cache_(cache)
22 {
23 }
24 
Execute() const25 void DnsResolvConfig::DelayedTaskWrapper::Execute() const
26 {
27     cache_.Delete(hostName_);
28 }
29 
operator <(const DelayedTaskWrapper & other) const30 bool DnsResolvConfig::DelayedTaskWrapper::operator<(const DelayedTaskWrapper &other) const
31 {
32     return hostName_ < other.hostName_;
33 }
34 
DnsResolvConfig()35 DnsResolvConfig::DnsResolvConfig()
36     : netId_(0), netIdIsSet_(false), revisionId_(0), timeoutMsec_(0), retryCount_(0), isIpv6Enable_(false),
37     isUserDefinedDnsServer_(false)
38 {
39 }
40 
EnableIpv6()41 void DnsResolvConfig::EnableIpv6()
42 {
43     isIpv6Enable_ = true;
44 }
45 
IsIpv6Enable()46 bool DnsResolvConfig::IsIpv6Enable()
47 {
48     return isIpv6Enable_;
49 }
50 
SetNetId(uint16_t netId)51 void DnsResolvConfig::SetNetId(uint16_t netId)
52 {
53     if (netIdIsSet_) {
54         return;
55     }
56     netIdIsSet_ = true;
57     netId_ = netId;
58 }
59 
GetNetId() const60 uint16_t DnsResolvConfig::GetNetId() const
61 {
62     return netId_;
63 }
64 
SetTimeoutMsec(int32_t baseTimeoutMsec)65 void DnsResolvConfig::SetTimeoutMsec(int32_t baseTimeoutMsec)
66 {
67     timeoutMsec_ = baseTimeoutMsec;
68 }
69 
GetTimeoutMsec() const70 uint16_t DnsResolvConfig::GetTimeoutMsec() const
71 {
72     return timeoutMsec_;
73 }
74 
SetRetryCount(uint8_t retryCount)75 void DnsResolvConfig::SetRetryCount(uint8_t retryCount)
76 {
77     retryCount_ = retryCount;
78 }
79 
GetRetryCount() const80 uint8_t DnsResolvConfig::GetRetryCount() const
81 {
82     return retryCount_;
83 }
84 
SetServers(const std::vector<std::string> & servers)85 void DnsResolvConfig::SetServers(const std::vector<std::string> &servers)
86 {
87     nameServers_ = servers;
88     revisionId_++;
89 }
90 
GetServers() const91 std::vector<std::string> DnsResolvConfig::GetServers() const
92 {
93     return nameServers_;
94 }
95 
SetDomains(const std::vector<std::string> & domains)96 void DnsResolvConfig::SetDomains(const std::vector<std::string> &domains)
97 {
98     searchDomains_ = domains;
99 }
100 
GetDomains() const101 std::vector<std::string> DnsResolvConfig::GetDomains() const
102 {
103     return searchDomains_;
104 }
105 
GetCache()106 NetManagerStandard::LRUCache<AddrInfo> &DnsResolvConfig::GetCache()
107 {
108     return cache_;
109 }
110 
SetCacheDelayed(const std::string & hostName)111 void DnsResolvConfig::SetCacheDelayed(const std::string &hostName)
112 {
113     auto wrapper = std::make_shared<DelayedTaskWrapper>(hostName, cache_);
114     delayedQueue_.Put(wrapper);
115 }
116 
SetUserDefinedServerFlag(bool flag)117 void DnsResolvConfig::SetUserDefinedServerFlag(bool flag)
118 {
119     isUserDefinedDnsServer_ = flag;
120 }
121 
IsUserDefinedServer()122 bool DnsResolvConfig::IsUserDefinedServer()
123 {
124     return isUserDefinedDnsServer_;
125 }
126 } // namespace OHOS::nmd
127