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.
18 * @file FNet_NetAccountInfoImpl.cpp
19 * @brief This is the implementation for the %_NetAccountInfoImpl class.
22 #include <net_connection.h>
23 #include <FBaseString.h>
24 #include <FNetNetTypes.h>
25 #include <FNetNetEndPoint.h>
26 #include <FNetNetAccountInfo.h>
27 #include <FBaseSysLog.h>
28 #include <FBase_StringConverter.h>
29 #include "FNet_NetTypes.h"
30 #include "FNet_NetAccountInfoImpl.h"
31 #include "FNet_NetAccountDatabase.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Net::Wifi;
37 namespace Tizen { namespace Net {
39 static const int _MAX_ACCESS_POINT_NAME_LENGTH = 64;
41 _NetAccountInfoImpl::_NetAccountInfoImpl(void)
42 : __accountId(INVALID_HANDLE)
45 , __authType(NET_NAPAUTH_NONE)
49 , __bearerType(NET_BEARER_NONE)
50 , __protocolType(NET_PROTO_TYPE_NONE)
51 , __localAddressScheme(NET_ADDRESS_SCHEME_NONE)
52 , __dnsAddressScheme(NET_ADDRESS_SCHEME_NONE)
53 , __pLocalAddress(null)
54 , __pPrimaryDnsAddress(null)
55 , __pSecondaryDnsAddress(null)
56 , __pProxyAddress(null)
61 _NetAccountInfoImpl::~_NetAccountInfoImpl(void)
66 _NetAccountInfoImpl::Construct(const _NetAccountInfoImpl& netAccountInfo)
69 unique_ptr<IpAddress> pLocalAddress;
70 unique_ptr<IpAddress> pPrimaryDnsAddress;
71 unique_ptr<IpAddress> pSecondaryDnsAddress;
72 unique_ptr<NetEndPoint> pProxyAddress;
74 SysAssertf(__bearerType == NET_BEARER_NONE,
75 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
77 SysTryReturnResult(NID_NET, netAccountInfo.__bearerType != NET_BEARER_NONE, E_INVALID_ARG,
78 "Invalid argument is used. Network bearer type is invalid.");
80 if (netAccountInfo.__pLocalAddress != null)
82 pLocalAddress.reset(netAccountInfo.__pLocalAddress->CloneN());
83 SysTryReturnResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
86 if (netAccountInfo.__pPrimaryDnsAddress != null)
88 pPrimaryDnsAddress.reset(netAccountInfo.__pPrimaryDnsAddress->CloneN());
89 SysTryReturnResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
92 if (netAccountInfo.__pSecondaryDnsAddress != null)
94 pSecondaryDnsAddress.reset(netAccountInfo.__pSecondaryDnsAddress->CloneN());
95 SysTryReturnResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
98 if (netAccountInfo.__pProxyAddress != null)
100 pProxyAddress.reset(new (std::nothrow) NetEndPoint(*netAccountInfo.__pProxyAddress));
101 SysTryReturnResult(NID_NET, pProxyAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
104 __accountId = netAccountInfo.__accountId;
105 __accountName = netAccountInfo.__accountName;
106 __accessPointName = netAccountInfo.__accessPointName;
107 __authType = netAccountInfo.__authType;
108 __authId = netAccountInfo.__authId;
109 __authPassword = netAccountInfo.__authPassword;
110 __homeUrl = netAccountInfo.__homeUrl;
111 __bearerType = netAccountInfo.__bearerType;
112 __protocolType = netAccountInfo.__protocolType;
113 __localAddressScheme = netAccountInfo.__localAddressScheme;
114 __dnsAddressScheme = netAccountInfo.__dnsAddressScheme;
115 __pLocalAddress = move(pLocalAddress);
116 __pPrimaryDnsAddress = move(pPrimaryDnsAddress);
117 __pSecondaryDnsAddress = move(pSecondaryDnsAddress);
118 __pProxyAddress = move(pProxyAddress);
119 __isReadOnly = netAccountInfo.__isReadOnly;
125 _NetAccountInfoImpl::Construct(void)
127 SysAssertf(__bearerType == NET_BEARER_NONE,
128 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
130 __bearerType = NET_BEARER_PS;
136 _NetAccountInfoImpl::Construct(NetAccountInfo* pAccountInfo, void* pProfileHandle)
138 result r = E_SUCCESS;
139 NetAccountId accountId = INVALID_HANDLE;
141 String accessPointName;
142 NetNapAuthType authType = NET_NAPAUTH_NONE;
146 NetBearerType bearerType;
147 NetProtocolType protocolType;
148 NetAddressScheme localAddressScheme;
149 NetAddressScheme dnsAddressScheme;
150 std::unique_ptr<IpAddress> pLocalAddress;
151 std::unique_ptr<IpAddress> pPrimaryDnsAddress;
152 std::unique_ptr<IpAddress> pSecondaryDnsAddress;
153 std::unique_ptr<NetEndPoint> pProxyAddress;
154 bool isReadOnly = true;
155 int ret = CONNECTION_ERROR_NONE;
156 connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileHandle);
158 SysAssertf(__bearerType == NET_BEARER_NONE,
159 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
161 SysTryReturnResult(NID_NET, pAccountInfo != null, E_INVALID_ARG, "Invalid argument is used. The account info is null.");
162 SysTryReturnResult(NID_NET, profileHandle != null, E_INVALID_ARG, "Invalid argument is used. The profile handle is null.");
164 connection_profile_type_e profileType = CONNECTION_PROFILE_TYPE_CELLULAR;
165 ret = connection_profile_get_type(profileHandle, &profileType);
166 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
167 "A system error has been occurred. The return value from connection_profile_get_type() is %d", ret);
169 if (profileType == CONNECTION_PROFILE_TYPE_CELLULAR)
172 char* pProfileName = null;
174 connection_cellular_service_type_e serviceType = CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN;
175 connection_cellular_auth_type_e netAuthType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
176 char* pAuthId = null;
177 char* pAuthPassword = null;
178 char* pHomeUrl = null;
180 ret = connection_profile_get_id(profileHandle, &pProfileName);
181 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
182 "A system error has been occurred. The return value from connection_profile_get_id() is %d", ret);
184 profileName = String(pProfileName);
187 r = _NetAccountDatabase::GetAccountIdByProfileName(profileName, accountId);
188 SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
189 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
190 "A system error has been occurred. Failed to get the account Id from DB.");
192 r = _NetAccountDatabase::GetAccountName(accountId, accountName);
193 SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
194 SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
195 "A system error has been occurred. Failed to get the account name from DB.");
197 connection_profile_get_cellular_service_type(profileHandle, &serviceType);
198 if ((serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_MMS) || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS))
200 bearerType = NET_BEARER_MMS;
203 else if ((serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET) || (serviceType == CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET))
205 bearerType = NET_BEARER_PS;
210 bearerType = NET_BEARER_PS;
214 ret = connection_profile_get_cellular_apn(profileHandle, &pApn);
215 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
216 "A system error has been occurred. The return value from connection_profile_get_cellular_apn() is %d", ret);
218 accessPointName = String(pApn);
221 ret = connection_profile_get_cellular_auth_info(profileHandle, &netAuthType, &pAuthId, &pAuthPassword);
222 if (netAuthType == CONNECTION_CELLULAR_AUTH_TYPE_PAP)
224 authType = NET_NAPAUTH_PAP;
226 else if (netAuthType == CONNECTION_CELLULAR_AUTH_TYPE_CHAP)
228 authType = NET_NAPAUTH_CHAP;
232 authType = NET_NAPAUTH_NONE;
237 authId = String(pAuthId);
241 if (pAuthPassword != null)
243 authPassword = String(pAuthPassword);
247 ret = connection_profile_get_cellular_home_url(profileHandle, &pHomeUrl);
248 if ((ret == CONNECTION_ERROR_NONE) && (pHomeUrl != null))
250 homeUrl = String(pHomeUrl);
254 else if (profileType == CONNECTION_PROFILE_TYPE_WIFI)
256 accountId = _DEFAULT_WIFI_ACCOUNT_ID;
257 bearerType = NET_BEARER_WIFI;
261 SysLogException(NID_NET, E_INVALID_ARG, "[%s] Invalid argument is used. The profile info is invalid.", GetErrorMessage(E_INVALID_ARG));
262 return E_INVALID_ARG;
265 protocolType = NET_PROTO_TYPE_IPV4;
267 connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
268 ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
269 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
270 "A system error has been occurred. The return value from connection_profile_get_ip_config_type() is %d", ret);
271 if ((ipConfigType == CONNECTION_IP_CONFIG_TYPE_STATIC) || (ipConfigType == CONNECTION_IP_CONFIG_TYPE_FIXED))
273 localAddressScheme = NET_ADDRESS_SCHEME_STATIC;
274 dnsAddressScheme = NET_ADDRESS_SCHEME_STATIC;
278 localAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
279 dnsAddressScheme = NET_ADDRESS_SCHEME_DYNAMIC;
282 char* pIpAddr = null;
285 ret = connection_profile_get_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
286 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
288 ipAddr = String(pIpAddr);
289 pLocalAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
292 SysTryReturnResult(NID_NET, pLocalAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
295 ret = connection_profile_get_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
296 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
298 ipAddr = String(pIpAddr);
299 pPrimaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
302 SysTryReturnResult(NID_NET, pPrimaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
305 ret = connection_profile_get_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &pIpAddr);
306 if ((ret == CONNECTION_ERROR_NONE) && (pIpAddr != null))
308 ipAddr = String(pIpAddr);
309 pSecondaryDnsAddress.reset(new (std::nothrow) Ip4Address(ipAddr));
312 SysTryReturnResult(NID_NET, pSecondaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
315 char* pProxyAddr = null;
317 int delimeterIndex = 0;
319 ret = connection_profile_get_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &pProxyAddr);
320 if ((ret == CONNECTION_ERROR_NONE) && (pProxyAddr != null))
322 proxyAddr = String(pProxyAddr);
325 r = proxyAddr.IndexOf(L":", 0, delimeterIndex);
332 r = proxyAddr.SubString(0, delimeterIndex, proxyIpAddr);
333 r = proxyAddr.SubString(delimeterIndex+1, proxyPort);
335 Ip4Address address(proxyIpAddr);
336 Integer::Parse(proxyPort, port);
338 pProxyAddress.reset(new (std::nothrow) NetEndPoint(address, port));
339 SysTryReturnResult(NID_NET, pProxyAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
343 __accountId = accountId;
344 __accountName = accountName;
345 __accessPointName = accessPointName;
346 __authType = authType;
348 __authPassword = authPassword;
350 __bearerType = bearerType;
351 __protocolType = protocolType;
352 __localAddressScheme = localAddressScheme;
353 __dnsAddressScheme = dnsAddressScheme;
354 __pLocalAddress = move(pLocalAddress);
355 __pPrimaryDnsAddress = move(pPrimaryDnsAddress);
356 __pSecondaryDnsAddress = move(pSecondaryDnsAddress);
357 __pProxyAddress = move(pProxyAddress);
358 __isReadOnly = isReadOnly;
360 pAccountInfo->__pNetAccountInfoImpl = this;
366 _NetAccountInfoImpl::GetAccountId(void) const
370 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
376 _NetAccountInfoImpl::SetAccountId(NetAccountId accountId)
378 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
380 __accountId = accountId;
386 _NetAccountInfoImpl::GetAccountName(void) const
390 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
392 return __accountName;
396 _NetAccountInfoImpl::SetAccountName(const String& accountName)
398 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
400 __accountName = accountName;
402 if (__accountName.GetLength() > _MAX_ACCOUNT_NAME_LENGTH)
404 SysLog(NID_NET, "AccountName's length is over [%d], so truncate it.", _MAX_ACCOUNT_NAME_LENGTH);
406 __accountName.SetLength(_MAX_ACCOUNT_NAME_LENGTH);
413 _NetAccountInfoImpl::GetProtocolType(void) const
417 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
419 return __protocolType;
423 _NetAccountInfoImpl::SetProtocolType(NetProtocolType netProtocolType)
425 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
427 __protocolType = netProtocolType;
433 _NetAccountInfoImpl::GetAccessPointName(void) const
437 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
439 return __accessPointName;
443 _NetAccountInfoImpl::SetAccessPointName(const String& accessPointName)
445 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
447 __accessPointName = accessPointName;
449 if (__accessPointName.GetLength() > _MAX_ACCESS_POINT_NAME_LENGTH)
451 SysLog(NID_NET, "AccessPointName's length[%d] is over [%d], so truncate it.",
452 __accessPointName.GetLength(), _MAX_ACCESS_POINT_NAME_LENGTH);
454 __accessPointName.SetLength(_MAX_ACCESS_POINT_NAME_LENGTH);
461 _NetAccountInfoImpl::GetLocalAddressScheme(void) const
465 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
467 return __localAddressScheme;
471 _NetAccountInfoImpl::GetLocalAddress(void) const
475 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
477 SysTryReturn(NID_NET, __localAddressScheme == NET_ADDRESS_SCHEME_STATIC, null, E_INVALID_OPERATION,
478 "[%s] The operation is not allowed on dynamic address scheme instance.", GetErrorMessage(E_INVALID_OPERATION));
480 return __pLocalAddress.get();
484 _NetAccountInfoImpl::SetLocalAddress(NetAddressScheme localAddrScheme, const IpAddress* pLocalAddress)
486 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
488 std::unique_ptr<IpAddress> pTempAddress;
490 if (localAddrScheme == NET_ADDRESS_SCHEME_STATIC)
492 SysLog(NID_NET, "Local address scheme is static.");
494 SysTryReturnResult(NID_NET, pLocalAddress != null, E_INVALID_ARG,
495 "Invalid argument is used. Address scheme is static but local address is null.");
497 pTempAddress.reset(pLocalAddress->CloneN());
498 SysTryReturnResult(NID_NET, pTempAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
500 else if (localAddrScheme == NET_ADDRESS_SCHEME_DYNAMIC)
502 SysLog(NID_NET, "Local address scheme is dynamic.");
506 SysLogException(NID_NET, E_INVALID_ARG, "[%s] Invalid argument is used. The address scheme is invalid.", GetErrorMessage(E_INVALID_ARG));
508 return E_INVALID_ARG;
511 __localAddressScheme = localAddrScheme;
512 __pLocalAddress.reset(pTempAddress.release());
518 _NetAccountInfoImpl::GetDnsAddressScheme(void) const
522 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
524 return __dnsAddressScheme;
528 _NetAccountInfoImpl::GetPrimaryDnsAddress(void) const
532 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
534 SysTryReturn(NID_NET, __dnsAddressScheme == NET_ADDRESS_SCHEME_STATIC, null, E_INVALID_OPERATION,
535 "[%s] The operation is not allowed on dynamic address scheme instance.", GetErrorMessage(E_INVALID_OPERATION));
537 return __pPrimaryDnsAddress.get();
541 _NetAccountInfoImpl::GetSecondaryDnsAddress(void) const
545 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
547 SysTryReturn(NID_NET, __dnsAddressScheme == NET_ADDRESS_SCHEME_STATIC, null, E_INVALID_OPERATION,
548 "[%s] The operation is not allowed on dynamic address scheme instance.", GetErrorMessage(E_INVALID_OPERATION));
550 return __pSecondaryDnsAddress.get();
554 _NetAccountInfoImpl::SetDnsAddress(NetAddressScheme dnsAddressScheme, const IpAddress* pPrimaryDnsAddress,
555 const IpAddress* pSecondaryDnsAddress)
557 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
559 std::unique_ptr<IpAddress> pTempPrimaryDnsAddress;
560 std::unique_ptr<IpAddress> pTempSecondaryDnsAddress;
562 if (dnsAddressScheme == NET_ADDRESS_SCHEME_STATIC)
564 SysLog(NID_NET, "DNS address scheme is static.");
566 SysTryReturnResult(NID_NET, pPrimaryDnsAddress != null, E_INVALID_ARG,
567 "Invalid argument is used. Address scheme is static but primary dns address is null.");
569 pTempPrimaryDnsAddress.reset(pPrimaryDnsAddress->CloneN());
570 SysTryReturnResult(NID_NET, pTempPrimaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
572 if (pSecondaryDnsAddress != null)
574 pTempSecondaryDnsAddress.reset(pSecondaryDnsAddress->CloneN());
575 SysTryReturnResult(NID_NET, pTempSecondaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
578 else if (dnsAddressScheme == NET_ADDRESS_SCHEME_DYNAMIC)
580 SysLog(NID_NET, "DNS address scheme is dynamic.");
584 SysLogException(NID_NET, E_INVALID_ARG, "[%s] Invalid argument is used. The address scheme is invalid.", GetErrorMessage(E_INVALID_ARG));
586 return E_INVALID_ARG;
589 __dnsAddressScheme = dnsAddressScheme;
590 __pPrimaryDnsAddress.reset(pTempPrimaryDnsAddress.release());
591 __pSecondaryDnsAddress.reset(pTempSecondaryDnsAddress.release());
597 _NetAccountInfoImpl::GetProxyAddress(void) const
601 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
603 return __pProxyAddress.get();
607 _NetAccountInfoImpl::SetProxyAddress(const NetEndPoint* pProxyEndPoint)
609 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
611 std::unique_ptr<NetEndPoint> pProxyAddress;
613 if (pProxyEndPoint != null)
615 pProxyAddress.reset(new (std::nothrow) NetEndPoint(*pProxyEndPoint));
616 SysTryReturnResult(NID_NET, pProxyAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
619 __pProxyAddress.reset(pProxyAddress.release());
625 _NetAccountInfoImpl::GetAuthenticationInfo(NetNapAuthType& authenticationType, String& id, String& password) const
627 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
629 authenticationType = __authType;
631 password = __authPassword;
637 _NetAccountInfoImpl::SetAuthenticationInfo(NetNapAuthType authenticationType, const String& id, const String& password)
639 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
641 __authType = authenticationType;
643 __authPassword = password;
649 _NetAccountInfoImpl::GetBearerType(void) const
653 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
659 _NetAccountInfoImpl::SetBearerType(NetBearerType bearerType)
661 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
663 __bearerType = bearerType;
669 _NetAccountInfoImpl::GetHomeUrl(void) const
675 _NetAccountInfoImpl::SetHomeUrl(const String& homeUrl)
681 _NetAccountInfoImpl::GetMaximumLengthOfId(void) const
683 return _MAX_AUTH_ID_LENGTH;
687 _NetAccountInfoImpl::GetMaximumLengthOfPassword(void) const
689 return _MAX_AUTH_PASSWORD_LENGTH;
693 _NetAccountInfoImpl::GetMaximumLengthOfAccountName(void) const
695 return _MAX_ACCOUNT_NAME_LENGTH;
699 _NetAccountInfoImpl::IsReadOnly(void) const
703 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
709 _NetAccountInfoImpl::ConvertToProfileInfo(void* pProfileHandle) const
711 result r = E_SUCCESS;
712 connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileHandle);
713 int ret = CONNECTION_ERROR_NONE;
714 connection_cellular_auth_type_e authType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
715 connection_ip_config_type_e ipConfigType = CONNECTION_IP_CONFIG_TYPE_NONE;
717 unique_ptr<char[]> pApn;
718 unique_ptr<char[]> pAuthId;
719 unique_ptr<char[]> pAuthPassword;
720 unique_ptr<char[]> pHomeUrl;
721 unique_ptr<char[]> pLocalAddr;
722 unique_ptr<char[]> pPrimaryDnsAddr;
723 unique_ptr<char[]> pSecondaryDnsAddr;
724 unique_ptr<char[]> pProxyAddr;
727 SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ARG, "Profile handle is null.");
728 SysTryReturnResult(NID_NET, ((__bearerType == NET_BEARER_PS) || (__bearerType == NET_BEARER_MMS)), E_INVALID_ARG,
729 "Invalid argument is used. BearerType is NOT PS. bearerType=%d", __bearerType);
731 ret = connection_profile_set_cellular_service_type(profileHandle, CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
732 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
733 "A system error has been occurred. The return value from connection_profile_set_cellular_service_type() is %d", ret);
735 if (!__accessPointName.IsEmpty())
737 pApn.reset(_StringConverter::CopyToCharArrayN(__accessPointName));
738 SysTryReturnResult(NID_NET, pApn != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
740 ret = connection_profile_set_cellular_apn(profileHandle, pApn.get());
741 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
742 "A system error has been occurred. The return value from connection_profile_set_cellular_apn() is %d", ret);
745 if (__authType == NET_NAPAUTH_PAP)
747 authType = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
749 else if (__authType == NET_NAPAUTH_CHAP)
751 authType = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
755 authType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
758 if (!__authId.IsEmpty())
760 pAuthId.reset(_StringConverter::CopyToCharArrayN(__authId));
761 SysTryReturnResult(NID_NET, pAuthId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
764 if (!__authPassword.IsEmpty())
766 pAuthPassword.reset(_StringConverter::CopyToCharArrayN(__authPassword));
767 SysTryReturnResult(NID_NET, pAuthPassword != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
770 if ((pAuthId != null) && (pAuthPassword != null))
772 ret = connection_profile_set_cellular_auth_info(profileHandle, authType, pAuthId.get(), pAuthPassword.get());
776 ret = connection_profile_set_cellular_auth_info(profileHandle, authType, " ", " ");
778 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
779 "A system error has been occurred. The return value from connection_profile_set_cellular_auth_info() is %d", ret);
781 if (!__homeUrl.IsEmpty())
783 pHomeUrl.reset(_StringConverter::CopyToCharArrayN(__homeUrl));
784 SysTryReturnResult(NID_NET, pHomeUrl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
786 ret = connection_profile_set_cellular_home_url(profileHandle, pHomeUrl.get());
790 ret = connection_profile_set_cellular_home_url(profileHandle, " ");
792 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
793 "A system error has been occurred. The return value from connection_profile_set_cellular_home_url() is %d", ret);
795 ret = connection_profile_get_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, &ipConfigType);
797 if (ipConfigType != CONNECTION_IP_CONFIG_TYPE_FIXED)
799 if (__localAddressScheme == NET_ADDRESS_SCHEME_STATIC)
801 SysTryReturnResult(NID_NET, __pLocalAddress != null, E_INVALID_ARG, "Invalid argument is used. Local Addr Scheme is static, but local addr is null.");
803 ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_STATIC);
804 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
805 "A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
807 pLocalAddr.reset(_StringConverter::CopyToCharArrayN(__pLocalAddress->ToString()));
808 SysTryReturnResult(NID_NET, pLocalAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
810 ret = connection_profile_set_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pLocalAddr.get());
811 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
812 "A system error has been occurred. The return value from connection_profile_set_ip_address() is %d", ret);
816 ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
817 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
818 "A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
821 if (__pPrimaryDnsAddress != null)
823 pPrimaryDnsAddr.reset(_StringConverter::CopyToCharArrayN(__pPrimaryDnsAddress->ToString()));
824 SysTryReturnResult(NID_NET, pPrimaryDnsAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
826 ret = connection_profile_set_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, pPrimaryDnsAddr.get());
827 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
828 "A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", ret);
831 if (__pSecondaryDnsAddress != null)
833 pSecondaryDnsAddr.reset(_StringConverter::CopyToCharArrayN(__pSecondaryDnsAddress->ToString()));
834 SysTryReturnResult(NID_NET, pSecondaryDnsAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
836 ret = connection_profile_set_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, pSecondaryDnsAddr.get());
837 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
838 "A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", ret);
842 if (__pProxyAddress != null)
844 proxyAddr = __pProxyAddress->GetNetEndPoint();
845 if (!proxyAddr.IsEmpty())
847 ret = connection_profile_set_proxy_type(profileHandle, CONNECTION_PROXY_TYPE_MANUAL);
848 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
849 "A system error has been occurred. The return value from connection_profile_set_proxy_type() is %d", ret);
851 pProxyAddr.reset(_StringConverter::CopyToCharArrayN(proxyAddr));
852 SysTryReturnResult(NID_NET, pProxyAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
854 ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pProxyAddr.get());
858 ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, null);
863 ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, null);
865 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
866 "A system error has been occurred. The return value from connection_profile_set_proxy_address() is %d", ret);
872 _NetAccountInfoImpl::Equals(const Object& obj) const
874 const _NetAccountInfoImpl* pRhs = dynamic_cast <const _NetAccountInfoImpl*>(&obj);
881 if (__accountId != pRhs->__accountId ||
882 __accountName != pRhs->__accountName ||
883 __accessPointName != pRhs->__accessPointName ||
884 __authType != pRhs->__authType ||
885 __authId != pRhs->__authId ||
886 __authPassword != pRhs->__authPassword ||
887 __homeUrl != pRhs->__homeUrl ||
888 __bearerType != pRhs->__bearerType ||
889 __protocolType != pRhs->__protocolType ||
890 __localAddressScheme != pRhs->__localAddressScheme ||
891 __dnsAddressScheme != pRhs->__dnsAddressScheme ||
892 __isReadOnly != pRhs->__isReadOnly )
897 if (__pLocalAddress != null && pRhs->__pLocalAddress != null)
899 if (!__pLocalAddress->Equals(*pRhs->__pLocalAddress))
904 else if (__pLocalAddress != null || pRhs->__pLocalAddress != null)
909 if (__pPrimaryDnsAddress != null && pRhs->__pPrimaryDnsAddress != null)
911 if (!__pPrimaryDnsAddress->Equals(*pRhs->__pPrimaryDnsAddress))
916 else if (__pPrimaryDnsAddress != null || pRhs->__pPrimaryDnsAddress != null)
921 if (__pSecondaryDnsAddress != null && pRhs->__pSecondaryDnsAddress != null)
923 if (!__pSecondaryDnsAddress->Equals(*pRhs->__pSecondaryDnsAddress))
928 else if (__pSecondaryDnsAddress != null || pRhs->__pSecondaryDnsAddress != null)
933 if (__pProxyAddress != null && pRhs->__pProxyAddress != null)
935 if (!__pProxyAddress->Equals(*pRhs->__pProxyAddress))
940 else if (__pProxyAddress != null || pRhs->__pProxyAddress != null)
949 _NetAccountInfoImpl::GetHashCode(void) const
951 int hashCode = _HASH_CODE_INITIAL_VALUE;
953 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __accountId;
954 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __accountName.GetHashCode();
955 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __accessPointName.GetHashCode();
956 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __authType;
957 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __authId.GetHashCode();
958 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __authPassword.GetHashCode();
959 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __homeUrl.GetHashCode();
960 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __bearerType;
961 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __protocolType;
962 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __localAddressScheme;
963 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dnsAddressScheme;
965 if (__pLocalAddress != null)
967 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pLocalAddress->GetHashCode();
971 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
974 if (__pPrimaryDnsAddress != null)
976 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pPrimaryDnsAddress->GetHashCode();
980 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
983 if (__pSecondaryDnsAddress != null)
985 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pSecondaryDnsAddress->GetHashCode();
989 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
992 if (__pProxyAddress != null)
994 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pProxyAddress->GetHashCode();
998 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
1001 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isReadOnly ? 0 : 1);
1007 _NetAccountInfoImpl::CreateNetAccountInfoN(void* pProfileHandle)
1009 result r = E_SUCCESS;
1011 std::unique_ptr<NetAccountInfo> pNetAccountInfo(new (std::nothrow) NetAccountInfo());
1012 SysTryReturn(NID_NET, pNetAccountInfo != null, null, E_OUT_OF_MEMORY,
1013 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1015 unique_ptr<_NetAccountInfoImpl> pNetAccountInfoImpl(new (std::nothrow) _NetAccountInfoImpl());
1016 SysTryReturn(NID_NET, pNetAccountInfoImpl != null, null, E_OUT_OF_MEMORY,
1017 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1019 r = pNetAccountInfoImpl->Construct(pNetAccountInfo.get(), pProfileHandle);
1020 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1022 pNetAccountInfoImpl.release();
1024 return pNetAccountInfo.release();
1027 _NetAccountInfoImpl*
1028 _NetAccountInfoImpl::GetInstance(NetAccountInfo& netAccountInfo)
1030 return netAccountInfo.__pNetAccountInfoImpl;
1033 const _NetAccountInfoImpl*
1034 _NetAccountInfoImpl::GetInstance(const NetAccountInfo& netAccountInfo)
1036 return netAccountInfo.__pNetAccountInfoImpl;