Merge "Add the exception handling when using manual cert mode" into tizen_2.1
[platform/framework/native/net.git] / src / FNet_NetConnectionInfoImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                FNet_NetConnectionInfoImpl.cpp
19  * @brief               This is the implementation for the _NetConnectionInfoImpl class.
20  */
21
22 #include <net_connection.h>
23 #include <FBaseUtilStringUtil.h>
24 #include <FNetNetConnectionInfo.h>
25 #include <FNetIp4Address.h>
26 #include <FBaseSysLog.h>
27 #include "FNet_NetTypes.h"
28 #include "FNet_NetConnectionInfoImpl.h"
29
30 using namespace std;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Utility;
33
34 namespace Tizen { namespace Net {
35
36 _NetConnectionInfoImpl::_NetConnectionInfoImpl(void)
37         : __bearerType(NET_BEARER_NONE)
38         , __protocolType(NET_PROTO_TYPE_NONE)
39         , __localAddressScheme(NET_ADDRESS_SCHEME_NONE)
40         , __dnsAddressScheme(NET_ADDRESS_SCHEME_NONE)
41         , __pLocalAddress(null)
42         , __pSubnetMaskAddress(null)
43         , __pDefaultGatewayAddress(null)
44         , __pPrimaryDnsAddress(null)
45         , __pSecondaryDnsAddress(null)
46 {
47 }
48
49 _NetConnectionInfoImpl::~_NetConnectionInfoImpl(void)
50 {
51 }
52
53 NetBearerType
54 _NetConnectionInfoImpl::GetBearerType(void) const
55 {
56         return  __bearerType;
57 }
58
59 NetProtocolType
60 _NetConnectionInfoImpl::GetProtocolType(void) const
61 {
62         return __protocolType;
63 }
64
65 String
66 _NetConnectionInfoImpl::GetAccessPointName(void) const
67 {
68         return __apn;
69 }
70
71 NetAddressScheme
72 _NetConnectionInfoImpl::GetLocalAddressScheme(void) const
73 {
74         return __localAddressScheme;
75 }
76
77 const IpAddress*
78 _NetConnectionInfoImpl::GetLocalAddress(void) const
79 {
80         return __pLocalAddress.get();
81 }
82
83 NetAddressScheme
84 _NetConnectionInfoImpl::GetDnsAddressScheme(void) const
85 {
86         return __dnsAddressScheme;
87 }
88
89 const IpAddress*
90 _NetConnectionInfoImpl::GetPrimaryDnsAddress(void) const
91 {
92         return __pPrimaryDnsAddress.get();
93 }
94
95 const IpAddress*
96 _NetConnectionInfoImpl::GetSecondaryDnsAddress(void) const
97 {
98         return __pSecondaryDnsAddress.get();
99 }
100
101 const IpAddress*
102 _NetConnectionInfoImpl::GetSubnetMaskAddress(void) const
103 {
104         return __pSubnetMaskAddress.get();
105 }
106
107 const IpAddress*
108 _NetConnectionInfoImpl::GetDefaultGatewayAddress(void) const
109 {
110         return __pDefaultGatewayAddress.get();
111 }
112
113 String
114 _NetConnectionInfoImpl::GetDeviceName(void) const
115 {
116         return __deviceName;
117 }
118
119 String
120 _NetConnectionInfoImpl::GetProxyAddress(void) const
121 {
122         return __proxyAddress;
123 }
124
125 void
126 _NetConnectionInfoImpl::CopyFrom(const _NetConnectionInfoImpl* pSource)
127 {
128         const Ip4Address* pAddress = null;
129         unique_ptr<IpAddress> pLocalAddress;
130         unique_ptr<IpAddress> pSubnetMaskAddress;
131         unique_ptr<IpAddress> pDefaultGatewayAddress;
132         unique_ptr<IpAddress> pPrimaryDnsAddress;
133         unique_ptr<IpAddress> pSecondaryDnsAddress;
134
135         SysTryReturnVoidResult(NID_NET, pSource != null, E_INVALID_ARG,
136                         "[%s] Invalud argument is used. Source is null.", GetErrorMessage(E_INVALID_ARG));
137
138         pAddress = dynamic_cast<const Ip4Address*>(pSource->GetLocalAddress());
139         if (pAddress != null)
140         {
141                 pLocalAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
142                 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
143                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
144         }
145
146         pAddress = dynamic_cast<const Ip4Address*>(pSource->GetSubnetMaskAddress());
147         if (pAddress != null)
148         {
149                 pSubnetMaskAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
150                 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
151                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
152         }
153
154         pAddress = dynamic_cast<const Ip4Address*>(pSource->GetDefaultGatewayAddress());
155         if (pAddress != null)
156         {
157                 pDefaultGatewayAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
158                 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
159                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
160         }
161
162         pAddress = dynamic_cast<const Ip4Address*>(pSource->GetPrimaryDnsAddress());
163         if (pAddress != null)
164         {
165                 pPrimaryDnsAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
166                 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
167                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
168         }
169
170         pAddress = dynamic_cast<const Ip4Address*>(pSource->GetSecondaryDnsAddress());
171         if (pAddress != null)
172         {
173                 pSecondaryDnsAddress.reset(new (std::nothrow) Ip4Address(*pAddress));
174                 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
175                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
176         }
177
178         __bearerType = pSource->GetBearerType();
179         __protocolType = pSource->GetProtocolType();
180         __apn = pSource->GetAccessPointName();
181         __localAddressScheme = pSource->GetLocalAddressScheme();
182         __dnsAddressScheme = pSource->GetDnsAddressScheme();
183         __proxyAddress = pSource->GetProxyAddress();
184         __deviceName = pSource->GetDeviceName();
185
186         __pLocalAddress.reset(pLocalAddress.release());
187         __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
188         __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
189         __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
190         __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
191 }
192
193 void
194 _NetConnectionInfoImpl::Clear()
195 {
196         __bearerType = NET_BEARER_NONE;
197         __protocolType = NET_PROTO_TYPE_NONE;
198         __apn.Clear();
199         __deviceName.Clear();
200         __proxyAddress.Clear();
201         __localAddressScheme = NET_ADDRESS_SCHEME_NONE;
202         __dnsAddressScheme = NET_ADDRESS_SCHEME_NONE;
203
204         __pLocalAddress.reset(null);
205         __pSubnetMaskAddress.reset(null);
206         __pDefaultGatewayAddress.reset(null);
207         __pPrimaryDnsAddress.reset(null);
208         __pSecondaryDnsAddress.reset(null);
209 }
210
211 void
212 _NetConnectionInfoImpl::SetBearerType(NetBearerType bearerType)
213 {
214         __bearerType =  bearerType;
215 }
216
217 void
218 _NetConnectionInfoImpl::SetProtocolType(NetProtocolType protocolType)
219 {
220         __protocolType = protocolType;
221 }
222
223 void
224 _NetConnectionInfoImpl::SetAccessPointName(const String& apn)
225 {
226         __apn = apn;
227 }
228
229 void
230 _NetConnectionInfoImpl::SetLocalAddressScheme(NetAddressScheme localAddressScheme)
231 {
232         __localAddressScheme = localAddressScheme;
233 }
234
235 void
236 _NetConnectionInfoImpl::SetDnsAddressScheme(NetAddressScheme dnsAddressScheme)
237 {
238         __dnsAddressScheme = dnsAddressScheme;
239 }
240
241 void
242 _NetConnectionInfoImpl::SetLocalAddress(const String& localAddress)
243 {
244         unique_ptr<IpAddress> pLocalAddress(new (std::nothrow) Ip4Address(localAddress));
245         SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
246                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
247
248         __pLocalAddress.reset(pLocalAddress.release());
249 }
250
251 void
252 _NetConnectionInfoImpl::SetSubnetMaskAddress(const String& subnetMaskAddress)
253 {
254         unique_ptr<IpAddress> pSubnetMaskAddress(new (std::nothrow) Ip4Address(subnetMaskAddress));
255         SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
256                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
257
258         __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
259 }
260
261 void
262 _NetConnectionInfoImpl::SetDefaultGatewayAddress(const String& defaultGatewayAddress)
263 {
264         unique_ptr<IpAddress> pDefaultGatewayAddress(new (std::nothrow) Ip4Address(defaultGatewayAddress));
265         SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
266                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
267
268         __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
269 }
270
271 void
272 _NetConnectionInfoImpl::SetPrimaryDnsAddress(const String& primaryDnsAddress)
273 {
274         unique_ptr<IpAddress> pPrimaryDnsAddress(new (std::nothrow) Ip4Address(primaryDnsAddress));
275         SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
276                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
277
278         __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
279 }
280
281 void
282 _NetConnectionInfoImpl::SetSecondaryDnsAddress(const String& secondaryDnsAddress)
283 {
284         unique_ptr<IpAddress> pSecondaryDnsAddress(new (std::nothrow) Ip4Address(secondaryDnsAddress));
285         SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
286                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
287
288         __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
289 }
290
291 void
292 _NetConnectionInfoImpl::SetProxyAddress(const String& proxyAddress)
293 {
294         __proxyAddress = proxyAddress;
295 }
296
297 void
298 _NetConnectionInfoImpl::SetDeviceName(const String& deviceName)
299 {
300         __deviceName = deviceName;
301 }
302
303 void
304 _NetConnectionInfoImpl::Update(void* pProfileHandle, bool isDefault)
305 {
306         static const wchar_t _IP4_ADDRESS_EMPTY_ADDRESS[] = L":";
307         static const wchar_t _IP4_ADDRESS_DUMMY_ADDRESS[] = L"0.0.0.0";
308
309         NetBearerType bearerType = NET_BEARER_NONE;
310         NetProtocolType protocolType = NET_PROTO_TYPE_NONE;
311         String apn;
312         String deviceName;
313         String proxyAddress;
314         NetAddressScheme localAddressScheme = NET_ADDRESS_SCHEME_NONE;
315         NetAddressScheme dnsAddressScheme = NET_ADDRESS_SCHEME_NONE;
316         unique_ptr<IpAddress> pLocalAddress;
317         unique_ptr<IpAddress> pSubnetMaskAddress;
318         unique_ptr<IpAddress> pDefaultGatewayAddress;
319         unique_ptr<IpAddress> pPrimaryDnsAddress;
320         unique_ptr<IpAddress> pSecondaryDnsAddress;
321
322         int ret = CONNECTION_ERROR_NONE;
323         connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileHandle);
324         connection_profile_type_e type = CONNECTION_PROFILE_TYPE_WIFI;
325
326         SysLog(NID_NET, "Update() has been called with isDefault:%d", isDefault);
327
328         Clear();
329
330         if (pProfileHandle == null)
331         {
332                 return;
333         }
334
335         ret = connection_profile_get_type(profileHandle, &type);
336         SysLog(NID_NET, "The return value from connection_profile_get_type() is %d. Network type is %d", ret, type);
337
338         if (type == CONNECTION_PROFILE_TYPE_WIFI)
339         {
340                 SysLog(NID_NET, "Profile type is Wi-Fi.");
341                 bearerType = NET_BEARER_WIFI;
342         }
343         else if (type == CONNECTION_PROFILE_TYPE_CELLULAR)
344         {
345                 SysLog(NID_NET, "Profile type is Cellular.");
346
347                 char* pApn = null;
348                 ret = connection_profile_get_cellular_apn(profileHandle, &pApn);
349                 if ((ret == CONNECTION_ERROR_NONE) && (pApn != null))
350                 {
351                         apn = String(pApn);
352                         free(pApn);
353                 }
354
355                 bearerType = NET_BEARER_PS;
356         }
357         else
358         {
359                 // CONNECTION_PROFILE_TYPE_ETHERNET (For emulator: Treat ethernet as cellular.)
360                 SysLog(NID_NET, "Profile type is Ethernet.");
361                 bearerType = NET_BEARER_PS;
362         }
363
364         protocolType = NET_PROTO_TYPE_IPV4;
365
366         connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
367         ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
368         SysTryReturnVoidResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
369                         "[%s] A system error has been occurred. The return value from connection_profile_get_ip_config_type() is %d",
370                         GetErrorMessage(E_SYSTEM), ret);
371
372         if ((ipConfigType == CONNECTION_IP_CONFIG_TYPE_STATIC) || (ipConfigType == CONNECTION_IP_CONFIG_TYPE_FIXED))
373         {
374                 localAddressScheme = NET_ADDRESS_SCHEME_STATIC;
375                 dnsAddressScheme = NET_ADDRESS_SCHEME_STATIC;
376         }
377         else
378         {
379                 localAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
380                 dnsAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
381         }
382
383         char* pIpAddr = null;
384         String ipAddr;
385
386         ret = connection_profile_get_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
387         if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
388         {
389                 ipAddr = String(pIpAddr);
390                 free(pIpAddr);
391                 pIpAddr = null;
392                 pLocalAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
393                 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
394                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
395         }
396
397         ret = connection_profile_get_subnet_mask(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
398         if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
399         {
400                 ipAddr = String(pIpAddr);
401                 free(pIpAddr);
402                 pIpAddr = null;
403                 pSubnetMaskAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
404                 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
405                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
406         }
407
408         ret = connection_profile_get_gateway_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
409         {
410                 ipAddr = String(pIpAddr);
411                 free(pIpAddr);
412                 pIpAddr = null;
413                 pDefaultGatewayAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
414                 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
415                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
416         }
417
418         ret = connection_profile_get_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
419         if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
420         {
421                 ipAddr = String(pIpAddr);
422                 free(pIpAddr);
423                 pIpAddr = null;
424                 pPrimaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
425                 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
426                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
427         }
428
429         ret = connection_profile_get_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
430         if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
431         {
432                 ipAddr = String(pIpAddr);
433                 free(pIpAddr);
434                 pIpAddr = null;
435                 pSecondaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
436                 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
437                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
438         }
439
440         char* pProxyAddr = null;
441
442         ret = connection_profile_get_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxyAddr);
443         SysSecureLog(NID_NET, "The return value from connection_profile_get_proxy_address() is [%d], Proxy address is [%s]", ret, pProxyAddr);
444         if ((ret == CONNECTION_ERROR_NONE) && (pProxyAddr != null))
445         {
446                 proxyAddress = String(pProxyAddr);
447                 proxyAddress.Trim();
448                 free(pProxyAddr);
449
450                 if (!proxyAddress.IsEmpty())
451                 {
452                         if ((proxyAddress.StartsWith(_IP4_ADDRESS_DUMMY_ADDRESS, 0)) || (proxyAddress.StartsWith(_IP4_ADDRESS_EMPTY_ADDRESS, 0)))
453                         {
454                                 proxyAddress.Clear();
455                                 SysLog(NID_NET, "Proxy address is invalid, so clear it.");
456                         }
457                 }
458         }
459
460         if (isDefault)
461         {
462                 deviceName.Clear();
463         }
464         else
465         {
466                 char* pDeviceName = null;
467
468                 ret = connection_profile_get_network_interface_name(profileHandle, &pDeviceName);
469                 if ((ret == CONNECTION_ERROR_NONE) && (pDeviceName != null))
470                 {
471                         deviceName = String(pDeviceName);
472                         free(pDeviceName);
473                 }
474         }
475
476         __bearerType = bearerType;
477         __protocolType = protocolType;
478         __apn = apn;
479         __localAddressScheme = localAddressScheme;
480         __dnsAddressScheme = dnsAddressScheme;
481         __proxyAddress = proxyAddress;
482         __deviceName = deviceName;
483
484         __pLocalAddress.reset(pLocalAddress.release());
485         __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
486         __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
487         __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
488         __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
489 }
490
491 NetConnectionInfo*
492 _NetConnectionInfoImpl::CreateNetConnectionInfoN(void* pProfileHandle)
493 {
494         result r = E_SUCCESS;
495
496         unique_ptr<NetConnectionInfo> pNetConnectionInfo;
497         _NetConnectionInfoImpl* pNetConnectionInfoImpl = null;
498
499         SysTryReturn(NID_NET, pProfileHandle != null, null, E_INVALID_ARG,
500                         "[%s] Invalid argument is used. The profile info is null.", GetErrorMessage(E_INVALID_ARG));
501
502         pNetConnectionInfo.reset(new (std::nothrow) NetConnectionInfo());
503         SysTryReturn(NID_NET, pNetConnectionInfo != null, null, E_OUT_OF_MEMORY,
504                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
505
506         pNetConnectionInfoImpl = _NetConnectionInfoImpl::GetInstance(*pNetConnectionInfo);
507         SysTryReturn(NID_NET, pNetConnectionInfoImpl != null, null, E_OUT_OF_MEMORY,
508                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
509
510         pNetConnectionInfoImpl->Update(pProfileHandle);
511         r = GetLastResult();
512         SysTryReturn(NID_NET, pNetConnectionInfoImpl != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
513
514         return pNetConnectionInfo.release();
515 }
516
517 _NetConnectionInfoImpl::_NetConnectionInfoImpl(const _NetConnectionInfoImpl& value)
518 {
519         unique_ptr<IpAddress> pLocalAddress;
520         unique_ptr<IpAddress> pSubnetMaskAddress;
521         unique_ptr<IpAddress> pDefaultGatewayAddress;
522         unique_ptr<IpAddress> pPrimaryDnsAddress;
523         unique_ptr<IpAddress> pSecondaryDnsAddress;
524
525         if (value.__pLocalAddress != null)
526         {
527                 pLocalAddress.reset(value.__pLocalAddress->CloneN());
528                 SysTryReturnVoidResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY,
529                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
530         }
531
532         if (value.__pSubnetMaskAddress != null)
533         {
534                 pSubnetMaskAddress.reset(value.__pSubnetMaskAddress->CloneN());
535                 SysTryReturnVoidResult(NID_NET, pSubnetMaskAddress != null, E_OUT_OF_MEMORY,
536                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
537         }
538
539         if (value.__pDefaultGatewayAddress != null)
540         {
541                 pDefaultGatewayAddress.reset(value.__pDefaultGatewayAddress->CloneN());
542                 SysTryReturnVoidResult(NID_NET, pDefaultGatewayAddress != null, E_OUT_OF_MEMORY,
543                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
544         }
545
546         if (value.__pPrimaryDnsAddress != null)
547         {
548                 pPrimaryDnsAddress.reset(value.__pPrimaryDnsAddress->CloneN());
549                 SysTryReturnVoidResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY,
550                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
551         }
552
553         if (value.__pSecondaryDnsAddress != null)
554         {
555                 pSecondaryDnsAddress.reset(value.__pSecondaryDnsAddress->CloneN());
556                 SysTryReturnVoidResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY,
557                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
558         }
559
560         __bearerType = value.__bearerType;
561         __protocolType = value.__protocolType;
562         __apn = value.__apn;
563         __deviceName = value.__deviceName;
564         __proxyAddress = value.__proxyAddress;
565         __localAddressScheme = value.__localAddressScheme;
566         __dnsAddressScheme = value.__dnsAddressScheme;
567
568         __pLocalAddress.reset(pLocalAddress.release());
569         __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
570         __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
571         __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
572         __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
573 }
574
575 _NetConnectionInfoImpl&
576 _NetConnectionInfoImpl::operator =(const _NetConnectionInfoImpl& rhs)
577 {
578         if (this == &rhs)
579         {
580                 return *this;
581         }
582
583         unique_ptr<IpAddress> pLocalAddress;
584         unique_ptr<IpAddress> pSubnetMaskAddress;
585         unique_ptr<IpAddress> pDefaultGatewayAddress;
586         unique_ptr<IpAddress> pPrimaryDnsAddress;
587         unique_ptr<IpAddress> pSecondaryDnsAddress;
588
589         if (rhs.__pLocalAddress != null)
590         {
591                 pLocalAddress.reset(rhs.__pLocalAddress->CloneN());
592                 SysTryReturn(NID_NET, pLocalAddress != null, *this, E_OUT_OF_MEMORY,
593                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
594         }
595
596         if (rhs.__pSubnetMaskAddress != null)
597         {
598                 pSubnetMaskAddress.reset(rhs.__pSubnetMaskAddress->CloneN());
599                 SysTryReturn(NID_NET, pSubnetMaskAddress != null, *this, E_OUT_OF_MEMORY,
600                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
601         }
602
603         if (rhs.__pDefaultGatewayAddress != null)
604         {
605                 pDefaultGatewayAddress.reset(rhs.__pDefaultGatewayAddress->CloneN());
606                 SysTryReturn(NID_NET, pDefaultGatewayAddress != null, *this, E_OUT_OF_MEMORY,
607                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
608         }
609
610         if (rhs.__pPrimaryDnsAddress != null)
611         {
612                 pPrimaryDnsAddress.reset(rhs.__pPrimaryDnsAddress->CloneN());
613                 SysTryReturn(NID_NET, pPrimaryDnsAddress != null, *this, E_OUT_OF_MEMORY,
614                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
615         }
616
617         if (rhs.__pSecondaryDnsAddress != null)
618         {
619                 pSecondaryDnsAddress.reset(rhs.__pSecondaryDnsAddress->CloneN());
620                 SysTryReturn(NID_NET, pSecondaryDnsAddress != null, *this, E_OUT_OF_MEMORY,
621                                 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
622         }
623
624         __bearerType = rhs.__bearerType;
625         __protocolType = rhs.__protocolType;
626         __apn = rhs.__apn;
627         __deviceName = rhs.__deviceName;
628         __proxyAddress = rhs.__proxyAddress;
629         __localAddressScheme = rhs.__localAddressScheme;
630         __dnsAddressScheme = rhs.__dnsAddressScheme;
631
632         __pLocalAddress.reset(pLocalAddress.release());
633         __pSubnetMaskAddress.reset(pSubnetMaskAddress.release());
634         __pDefaultGatewayAddress.reset(pDefaultGatewayAddress.release());
635         __pPrimaryDnsAddress.reset(pPrimaryDnsAddress.release());
636         __pSecondaryDnsAddress.reset(pSecondaryDnsAddress.release());
637
638         return *this;
639 }
640
641 bool
642 _NetConnectionInfoImpl::Equals(const Object& obj) const
643 {
644         const _NetConnectionInfoImpl* pRhs = dynamic_cast <const _NetConnectionInfoImpl*>(&obj);
645
646         if (pRhs == null)
647         {
648                 return false;
649         }
650
651         if (__bearerType != pRhs->__bearerType ||
652                 __protocolType != pRhs->__protocolType ||
653                 __apn != pRhs->__apn ||
654                 __deviceName != pRhs->__deviceName ||
655                 __proxyAddress != pRhs->__proxyAddress ||
656                 __localAddressScheme != pRhs->__localAddressScheme ||
657                 __dnsAddressScheme != pRhs->__dnsAddressScheme )
658         {
659                 return false;
660         }
661
662         if (__pLocalAddress != null && pRhs->__pLocalAddress != null)
663         {
664                 if (!__pLocalAddress->Equals(*pRhs->__pLocalAddress))
665                 {
666                         return false;
667                 }
668         }
669         else if (__pLocalAddress != null || pRhs->__pLocalAddress != null)
670         {
671                 return false;
672         }
673
674         if (__pSubnetMaskAddress != null && pRhs->__pSubnetMaskAddress != null)
675         {
676                 if (!__pSubnetMaskAddress->Equals(*pRhs->__pSubnetMaskAddress))
677                 {
678                         return false;
679                 }
680         }
681         else if (__pSubnetMaskAddress != null || pRhs->__pSubnetMaskAddress != null)
682         {
683                 return false;
684         }
685
686         if (__pDefaultGatewayAddress != null && pRhs->__pDefaultGatewayAddress != null)
687         {
688                 if (!__pDefaultGatewayAddress->Equals(*pRhs->__pDefaultGatewayAddress))
689                 {
690                         return false;
691                 }
692         }
693         else if (__pDefaultGatewayAddress != null || pRhs->__pDefaultGatewayAddress != null)
694         {
695                 return false;
696         }
697
698         if (__pPrimaryDnsAddress != null && pRhs->__pPrimaryDnsAddress != null)
699         {
700                 if (!__pPrimaryDnsAddress->Equals(*pRhs->__pPrimaryDnsAddress))
701                 {
702                         return false;
703                 }
704         }
705         else if (__pPrimaryDnsAddress != null || pRhs->__pPrimaryDnsAddress != null)
706         {
707                 return false;
708         }
709
710         if (__pSecondaryDnsAddress != null && pRhs->__pSecondaryDnsAddress != null)
711         {
712                 if ( !__pSecondaryDnsAddress->Equals(*pRhs->__pSecondaryDnsAddress))
713                 {
714                         return false;
715                 }
716         }
717         else if (__pSecondaryDnsAddress != null || pRhs->__pSecondaryDnsAddress != null)
718         {
719                 return false;
720         }
721
722         return true;
723 }
724
725 int
726 _NetConnectionInfoImpl::GetHashCode(void) const
727 {
728         int hashCode = _HASH_CODE_INITIAL_VALUE;
729
730         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __bearerType;
731         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __protocolType;
732         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __apn.GetHashCode();
733         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __deviceName.GetHashCode();
734         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __proxyAddress.GetHashCode();
735         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __localAddressScheme;
736         hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dnsAddressScheme;
737
738         if (__pLocalAddress != null)
739         {
740                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pLocalAddress->GetHashCode();
741         }
742         else
743         {
744                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
745         }
746
747         if (__pSubnetMaskAddress != null)
748         {
749                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pSubnetMaskAddress->GetHashCode();
750         }
751         else
752         {
753                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
754         }
755
756         if (__pDefaultGatewayAddress != null)
757         {
758                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pDefaultGatewayAddress->GetHashCode();
759         }
760         else
761         {
762                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
763         }
764
765         if (__pPrimaryDnsAddress != null)
766         {
767                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pPrimaryDnsAddress->GetHashCode();
768         }
769         else
770         {
771                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
772         }
773
774         if (__pSecondaryDnsAddress != null)
775         {
776                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pSecondaryDnsAddress->GetHashCode();
777         }
778         else
779         {
780                 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
781         }
782
783         return hashCode;
784 }
785
786 _NetConnectionInfoImpl*
787 _NetConnectionInfoImpl::GetInstance(NetConnectionInfo& netConnectionInfo)
788 {
789         return netConnectionInfo.__pNetConnectionInfoImpl;
790 }
791
792 const _NetConnectionInfoImpl*
793 _NetConnectionInfoImpl::GetInstance(const NetConnectionInfo& netConnectionInfo)
794 {
795         return netConnectionInfo.__pNetConnectionInfoImpl;
796 }
797
798 } } // Tizen::Net