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[%d] is over [%d], so truncate it.",
405 __accountName.GetLength(), _MAX_ACCOUNT_NAME_LENGTH);
407 __accountName.SetLength(_MAX_ACCOUNT_NAME_LENGTH);
414 _NetAccountInfoImpl::GetProtocolType(void) const
418 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
420 return __protocolType;
424 _NetAccountInfoImpl::SetProtocolType(NetProtocolType netProtocolType)
426 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
428 __protocolType = netProtocolType;
434 _NetAccountInfoImpl::GetAccessPointName(void) const
438 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
440 return __accessPointName;
444 _NetAccountInfoImpl::SetAccessPointName(const String& accessPointName)
446 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
448 __accessPointName = accessPointName;
450 if (__accessPointName.GetLength() > _MAX_ACCESS_POINT_NAME_LENGTH)
452 SysLog(NID_NET, "AccessPointName's length[%d] is over [%d], so truncate it.",
453 __accessPointName.GetLength(), _MAX_ACCESS_POINT_NAME_LENGTH);
455 __accessPointName.SetLength(_MAX_ACCESS_POINT_NAME_LENGTH);
462 _NetAccountInfoImpl::GetLocalAddressScheme(void) const
466 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
468 return __localAddressScheme;
472 _NetAccountInfoImpl::GetLocalAddress(void) const
476 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
478 SysTryReturn(NID_NET, __localAddressScheme == NET_ADDRESS_SCHEME_STATIC, null, E_INVALID_OPERATION,
479 "[%s] The operation is not allowed on dynamic address scheme instance.", GetErrorMessage(E_INVALID_OPERATION));
481 return __pLocalAddress.get();
485 _NetAccountInfoImpl::SetLocalAddress(NetAddressScheme localAddrScheme, const IpAddress* pLocalAddress)
487 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
489 std::unique_ptr<IpAddress> pTempAddress;
491 if (localAddrScheme == NET_ADDRESS_SCHEME_STATIC)
493 SysLog(NID_NET, "Local address scheme is static.");
495 SysTryReturnResult(NID_NET, pLocalAddress != null, E_INVALID_ARG,
496 "Invalid argument is used. Address scheme is static but local address is null.");
498 pTempAddress.reset(pLocalAddress->CloneN());
499 SysTryReturnResult(NID_NET, pTempAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
501 else if (localAddrScheme == NET_ADDRESS_SCHEME_DYNAMIC)
503 SysLog(NID_NET, "Local address scheme is dynamic.");
507 SysLogException(NID_NET, E_INVALID_ARG, "[%s] Invalid argument is used. The address scheme is invalid.", GetErrorMessage(E_INVALID_ARG));
509 return E_INVALID_ARG;
512 __localAddressScheme = localAddrScheme;
513 __pLocalAddress.reset(pTempAddress.release());
519 _NetAccountInfoImpl::GetDnsAddressScheme(void) const
523 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
525 return __dnsAddressScheme;
529 _NetAccountInfoImpl::GetPrimaryDnsAddress(void) const
533 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
535 SysTryReturn(NID_NET, __dnsAddressScheme == NET_ADDRESS_SCHEME_STATIC, null, E_INVALID_OPERATION,
536 "[%s] The operation is not allowed on dynamic address scheme instance.", GetErrorMessage(E_INVALID_OPERATION));
538 return __pPrimaryDnsAddress.get();
542 _NetAccountInfoImpl::GetSecondaryDnsAddress(void) const
546 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
548 SysTryReturn(NID_NET, __dnsAddressScheme == NET_ADDRESS_SCHEME_STATIC, null, E_INVALID_OPERATION,
549 "[%s] The operation is not allowed on dynamic address scheme instance.", GetErrorMessage(E_INVALID_OPERATION));
551 return __pSecondaryDnsAddress.get();
555 _NetAccountInfoImpl::SetDnsAddress(NetAddressScheme dnsAddressScheme, const IpAddress* pPrimaryDnsAddress,
556 const IpAddress* pSecondaryDnsAddress)
558 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
560 std::unique_ptr<IpAddress> pTempPrimaryDnsAddress;
561 std::unique_ptr<IpAddress> pTempSecondaryDnsAddress;
563 if (dnsAddressScheme == NET_ADDRESS_SCHEME_STATIC)
565 SysLog(NID_NET, "DNS address scheme is static.");
567 SysTryReturnResult(NID_NET, pPrimaryDnsAddress != null, E_INVALID_ARG,
568 "Invalid argument is used. Address scheme is static but primary dns address is null.");
570 pTempPrimaryDnsAddress.reset(pPrimaryDnsAddress->CloneN());
571 SysTryReturnResult(NID_NET, pTempPrimaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
573 if (pSecondaryDnsAddress != null)
575 pTempSecondaryDnsAddress.reset(pSecondaryDnsAddress->CloneN());
576 SysTryReturnResult(NID_NET, pTempSecondaryDnsAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
579 else if (dnsAddressScheme == NET_ADDRESS_SCHEME_DYNAMIC)
581 SysLog(NID_NET, "DNS address scheme is dynamic.");
585 SysLogException(NID_NET, E_INVALID_ARG, "[%s] Invalid argument is used. The address scheme is invalid.", GetErrorMessage(E_INVALID_ARG));
587 return E_INVALID_ARG;
590 __dnsAddressScheme = dnsAddressScheme;
591 __pPrimaryDnsAddress.reset(pTempPrimaryDnsAddress.release());
592 __pSecondaryDnsAddress.reset(pTempSecondaryDnsAddress.release());
598 _NetAccountInfoImpl::GetProxyAddress(void) const
602 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
604 return __pProxyAddress.get();
608 _NetAccountInfoImpl::SetProxyAddress(const NetEndPoint* pProxyEndPoint)
610 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
612 std::unique_ptr<NetEndPoint> pProxyAddress;
614 if (pProxyEndPoint != null)
616 pProxyAddress.reset(new (std::nothrow) NetEndPoint(*pProxyEndPoint));
617 SysTryReturnResult(NID_NET, pProxyAddress != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
620 __pProxyAddress.reset(pProxyAddress.release());
626 _NetAccountInfoImpl::GetAuthenticationInfo(NetNapAuthType& authenticationType, String& id, String& password) const
628 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
630 authenticationType = __authType;
632 password = __authPassword;
638 _NetAccountInfoImpl::SetAuthenticationInfo(NetNapAuthType authenticationType, const String& id, const String& password)
640 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
642 __authType = authenticationType;
644 __authPassword = password;
650 _NetAccountInfoImpl::GetBearerType(void) const
654 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
660 _NetAccountInfoImpl::SetBearerType(NetBearerType bearerType)
662 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
664 __bearerType = bearerType;
670 _NetAccountInfoImpl::GetHomeUrl(void) const
676 _NetAccountInfoImpl::SetHomeUrl(const String& homeUrl)
682 _NetAccountInfoImpl::GetMaximumLengthOfId(void) const
684 return _MAX_AUTH_ID_LENGTH;
688 _NetAccountInfoImpl::GetMaximumLengthOfPassword(void) const
690 return _MAX_AUTH_PASSWORD_LENGTH;
694 _NetAccountInfoImpl::GetMaximumLengthOfAccountName(void) const
696 return _MAX_ACCOUNT_NAME_LENGTH;
700 _NetAccountInfoImpl::IsReadOnly(void) const
704 SysAssertf(__bearerType != NET_BEARER_NONE, "Not yet constructed. Construct() should be called before use.");
710 _NetAccountInfoImpl::ConvertToProfileInfo(void* pProfileHandle) const
712 result r = E_SUCCESS;
713 connection_profile_h profileHandle = static_cast<connection_profile_h>(pProfileHandle);
714 int ret = CONNECTION_ERROR_NONE;
715 connection_cellular_auth_type_e authType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
716 unique_ptr<char[]> pApn;
717 unique_ptr<char[]> pAuthId;
718 unique_ptr<char[]> pAuthPassword;
719 unique_ptr<char[]> pHomeUrl;
720 unique_ptr<char[]> pLocalAddr;
721 unique_ptr<char[]> pPrimaryDnsAddr;
722 unique_ptr<char[]> pSecondaryDnsAddr;
723 unique_ptr<char[]> pProxyAddr;
726 SysTryReturnResult(NID_NET, pProfileHandle != null, E_INVALID_ARG, "Profile handle is null.");
727 SysTryReturnResult(NID_NET, ((__bearerType == NET_BEARER_PS) || (__bearerType == NET_BEARER_MMS)), E_INVALID_ARG,
728 "Invalid argument is used. BearerType is NOT PS. bearerType=%d", __bearerType);
730 ret = connection_profile_set_cellular_service_type(profileHandle, CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
731 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
732 "A system error has been occurred. The return value from connection_profile_set_cellular_service_type() is %d", ret);
734 if (!__accessPointName.IsEmpty())
736 pApn.reset(_StringConverter::CopyToCharArrayN(__accessPointName));
737 SysTryReturnResult(NID_NET, pApn != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
739 ret = connection_profile_set_cellular_apn(profileHandle, pApn.get());
740 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
741 "A system error has been occurred. The return value from connection_profile_set_cellular_apn() is %d", ret);
744 if (__authType == NET_NAPAUTH_PAP)
746 authType = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
748 else if (__authType == NET_NAPAUTH_CHAP)
750 authType = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
754 authType = CONNECTION_CELLULAR_AUTH_TYPE_NONE;
757 if (!__authId.IsEmpty())
759 pAuthId.reset(_StringConverter::CopyToCharArrayN(__authId));
760 SysTryReturnResult(NID_NET, pAuthId != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
763 if (!__authPassword.IsEmpty())
765 pAuthPassword.reset(_StringConverter::CopyToCharArrayN(__authPassword));
766 SysTryReturnResult(NID_NET, pAuthPassword != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
769 if ((pAuthId != null) && (pAuthPassword != null))
771 ret = connection_profile_set_cellular_auth_info(profileHandle, authType, pAuthId.get(), pAuthPassword.get());
772 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
773 "A system error has been occurred. The return value from connection_profile_set_cellular_auth_info() is %d", ret);
776 if (!__homeUrl.IsEmpty())
778 pHomeUrl.reset(_StringConverter::CopyToCharArrayN(__homeUrl));
779 SysTryReturnResult(NID_NET, pHomeUrl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
781 ret = connection_profile_set_cellular_home_url(profileHandle, pHomeUrl.get());
782 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
783 "A system error has been occurred. The return value from connection_profile_set_cellular_home_url() is %d", ret);
786 if (__localAddressScheme == NET_ADDRESS_SCHEME_STATIC)
788 SysTryReturnResult(NID_NET, __pLocalAddress != null, E_INVALID_ARG, "Invalid argument is used. Local Addr Scheme is static, but local addr is null.");
790 ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_STATIC);
791 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
792 "A system error has been occurred. The return value from connection_profile_set_ip_config_type() is %d", ret);
794 pLocalAddr.reset(_StringConverter::CopyToCharArrayN(__pLocalAddress->ToString()));
795 SysTryReturnResult(NID_NET, pLocalAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
797 ret = connection_profile_set_ip_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pLocalAddr.get());
798 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
799 "A system error has been occurred. The return value from connection_profile_set_ip_address() is %d", ret);
803 ret = connection_profile_set_ip_config_type(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
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);
808 if (__pPrimaryDnsAddress != null)
810 pPrimaryDnsAddr.reset(_StringConverter::CopyToCharArrayN(__pPrimaryDnsAddress->ToString()));
811 SysTryReturnResult(NID_NET, pPrimaryDnsAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
813 ret = connection_profile_set_dns_address(profileHandle, 1, CONNECTION_ADDRESS_FAMILY_IPV4, pPrimaryDnsAddr.get());
814 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
815 "A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", ret);
818 if (__pSecondaryDnsAddress != null)
820 pSecondaryDnsAddr.reset(_StringConverter::CopyToCharArrayN(__pSecondaryDnsAddress->ToString()));
821 SysTryReturnResult(NID_NET, pSecondaryDnsAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
823 ret = connection_profile_set_dns_address(profileHandle, 2, CONNECTION_ADDRESS_FAMILY_IPV4, pSecondaryDnsAddr.get());
824 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
825 "A system error has been occurred. The return value from connection_profile_set_dns_address() is %d", ret);
828 if (__pProxyAddress != null)
830 proxyAddr = __pProxyAddress->GetNetEndPoint();
831 if (!proxyAddr.IsEmpty())
833 ret = connection_profile_set_proxy_type(profileHandle, CONNECTION_PROXY_TYPE_MANUAL);
834 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
835 "A system error has been occurred. The return value from connection_profile_set_proxy_type() is %d", ret);
837 pProxyAddr.reset(_StringConverter::CopyToCharArrayN(proxyAddr));
838 SysTryReturnResult(NID_NET, pProxyAddr != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
840 ret = connection_profile_set_proxy_address(profileHandle, CONNECTION_ADDRESS_FAMILY_IPV4, pProxyAddr.get());
841 SysTryReturnResult(NID_NET, ret == CONNECTION_ERROR_NONE, E_SYSTEM,
842 "A system error has been occurred. The return value from connection_profile_set_proxy_address() is %d", ret);
850 _NetAccountInfoImpl::Equals(const Object& obj) const
852 const _NetAccountInfoImpl* pRhs = dynamic_cast <const _NetAccountInfoImpl*>(&obj);
859 if (__accountId != pRhs->__accountId ||
860 __accountName != pRhs->__accountName ||
861 __accessPointName != pRhs->__accessPointName ||
862 __authType != pRhs->__authType ||
863 __authId != pRhs->__authId ||
864 __authPassword != pRhs->__authPassword ||
865 __homeUrl != pRhs->__homeUrl ||
866 __bearerType != pRhs->__bearerType ||
867 __protocolType != pRhs->__protocolType ||
868 __localAddressScheme != pRhs->__localAddressScheme ||
869 __dnsAddressScheme != pRhs->__dnsAddressScheme ||
870 __isReadOnly != pRhs->__isReadOnly )
875 if (__pLocalAddress != null && pRhs->__pLocalAddress != null)
877 if (!__pLocalAddress->Equals(*pRhs->__pLocalAddress))
882 else if (__pLocalAddress != null || pRhs->__pLocalAddress != null)
887 if (__pPrimaryDnsAddress != null && pRhs->__pPrimaryDnsAddress != null)
889 if (!__pPrimaryDnsAddress->Equals(*pRhs->__pPrimaryDnsAddress))
894 else if (__pPrimaryDnsAddress != null || pRhs->__pPrimaryDnsAddress != null)
899 if (__pSecondaryDnsAddress != null && pRhs->__pSecondaryDnsAddress != null)
901 if (!__pSecondaryDnsAddress->Equals(*pRhs->__pSecondaryDnsAddress))
906 else if (__pSecondaryDnsAddress != null || pRhs->__pSecondaryDnsAddress != null)
911 if (__pProxyAddress != null && pRhs->__pProxyAddress != null)
913 if (!__pProxyAddress->Equals(*pRhs->__pProxyAddress))
918 else if (__pProxyAddress != null || pRhs->__pProxyAddress != null)
927 _NetAccountInfoImpl::GetHashCode(void) const
929 int hashCode = _HASH_CODE_INITIAL_VALUE;
931 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __accountId;
932 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __accountName.GetHashCode();
933 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __accessPointName.GetHashCode();
934 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __authType;
935 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __authId.GetHashCode();
936 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __authPassword.GetHashCode();
937 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __homeUrl.GetHashCode();
938 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __bearerType;
939 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __protocolType;
940 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __localAddressScheme;
941 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __dnsAddressScheme;
943 if (__pLocalAddress != null)
945 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pLocalAddress->GetHashCode();
949 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
952 if (__pPrimaryDnsAddress != null)
954 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pPrimaryDnsAddress->GetHashCode();
958 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
961 if (__pSecondaryDnsAddress != null)
963 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pSecondaryDnsAddress->GetHashCode();
967 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
970 if (__pProxyAddress != null)
972 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __pProxyAddress->GetHashCode();
976 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode;
979 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + (__isReadOnly ? 0 : 1);
985 _NetAccountInfoImpl::CreateNetAccountInfoN(void* pProfileHandle)
987 result r = E_SUCCESS;
989 std::unique_ptr<NetAccountInfo> pNetAccountInfo(new (std::nothrow) NetAccountInfo());
990 SysTryReturn(NID_NET, pNetAccountInfo != null, null, E_OUT_OF_MEMORY,
991 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
993 unique_ptr<_NetAccountInfoImpl> pNetAccountInfoImpl(new (std::nothrow) _NetAccountInfoImpl());
994 SysTryReturn(NID_NET, pNetAccountInfoImpl != null, null, E_OUT_OF_MEMORY,
995 "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
997 r = pNetAccountInfoImpl->Construct(pNetAccountInfo.get(), pProfileHandle);
998 SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1000 pNetAccountInfoImpl.release();
1002 return pNetAccountInfo.release();
1005 _NetAccountInfoImpl*
1006 _NetAccountInfoImpl::GetInstance(NetAccountInfo& netAccountInfo)
1008 return netAccountInfo.__pNetAccountInfoImpl;
1011 const _NetAccountInfoImpl*
1012 _NetAccountInfoImpl::GetInstance(const NetAccountInfo& netAccountInfo)
1014 return netAccountInfo.__pNetAccountInfoImpl;