2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @brief This is the implementation for the Dns class.
22 #include <unique_ptr.h>
24 #include <FNetIpAddress.h>
25 #include <FNetNetConnection.h>
26 #include <FNetIDnsEventListener.h>
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include "FNet_DnsImpl.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Security;
35 namespace Tizen { namespace Net
50 Dns::Construct(const NetConnection& netConnection, IDnsEventListener& listener)
54 SysAssertf(__pDnsImpl == null,
55 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57 unique_ptr<_DnsImpl> pDnsImpl(new (std::nothrow) _DnsImpl());
58 SysTryReturnResult(NID_NET, pDnsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
60 r = pDnsImpl->Construct(netConnection, listener);
61 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
63 __pDnsImpl = pDnsImpl.release();
69 Dns::Construct(IDnsEventListener& listener)
73 SysAssertf(__pDnsImpl == null,
74 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
76 unique_ptr<_DnsImpl> pDnsImpl(new (std::nothrow) _DnsImpl());
77 SysTryReturnResult(NID_NET, pDnsImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
79 r = pDnsImpl->Construct(listener);
80 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
82 __pDnsImpl = pDnsImpl.release();
88 Dns::GetHostByName(const String& hostName)
92 r = _AccessController::CheckUserPrivilege(_PRV_DNS);
93 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
94 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
96 SysAssertf(__pDnsImpl != null, "Not yet constructed. Construct() should be called before use.");
98 r = __pDnsImpl->GetHostByName(hostName);
99 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
105 Dns::GetHostByAddress(const IpAddress& ipAddress)
107 result r = E_SUCCESS;
109 r = _AccessController::CheckUserPrivilege(_PRV_DNS);
110 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
111 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "The application is not permitted to call this method.");
113 SysAssertf(__pDnsImpl != null, "Not yet constructed. Construct() should be called before use.");
115 r = __pDnsImpl->GetHostByAddress(ipAddress);
116 SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");