2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetHttpHttpCredentials.cpp
20 * @brief This is the implementation file for HttpCredentials class.
22 * This file contains the implementation of HttpCredentials class.
25 #include <FBaseBuffer.h>
26 #include <FBaseString.h>
27 #include <FNetHttpHttpCredentials.h>
28 #include <FBaseSysLog.h>
29 #include <FSec_AccessController.h>
30 #include "FNet_NetTypes.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Security;
35 namespace Tizen { namespace Net { namespace Http
38 HttpCredentials::HttpCredentials(void)
39 : __pHttpCredentialsImpl(null)
43 HttpCredentials::HttpCredentials(const String& username, const String& password)
45 __userName = username;
46 __password = password;
47 __pHttpCredentialsImpl = null;
50 HttpCredentials::HttpCredentials(const HttpCredentials& rhs)
52 __userName = rhs.__userName;
53 __password = rhs.__password;
54 __pHttpCredentialsImpl = null;
57 HttpCredentials::~HttpCredentials(void)
62 HttpCredentials::operator =(const HttpCredentials& rhs)
69 __userName = rhs.__userName;
70 __password = rhs.__password;
76 HttpCredentials::GetName(void) const
81 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
82 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
83 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, L"", r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
89 HttpCredentials::GetPassword(void) const
94 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
95 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
96 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, L"", r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
102 HttpCredentials::SetName(const String& userName)
104 result r = E_SUCCESS;
106 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
107 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
108 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "The application is not permitted to call this method.");
110 SysTryReturnResult(NID_NET_HTTP, userName.GetLength() > 0, E_INVALID_ARG,
111 "Failed to set user name of the credentials.");
113 __userName = userName;
118 HttpCredentials::SetPassword(const String& password)
120 result r = E_SUCCESS;
122 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
123 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED, E_OUT_OF_MEMORY);
124 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "The application is not permitted to call this method.");
126 SysTryReturnResult(NID_NET_HTTP, password.GetLength() > 0, E_INVALID_ARG,
127 "Failed to set password of the credentials.");
129 __password = password;
134 HttpCredentials::Equals(const Tizen::Base::Object& rhs) const
136 const HttpCredentials* pRhs = dynamic_cast< const HttpCredentials* >(&rhs);
143 if (__userName != pRhs->__userName ||
144 __password != pRhs->__password)
153 HttpCredentials::GetHashCode(void) const
155 int hashCode = _HASH_CODE_INITIAL_VALUE;
157 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __userName.GetHashCode();
158 hashCode = _HASH_CODE_COEFFICIENT_VALUE * hashCode + __password.GetHashCode();
163 } } } // Tizen::Net::Http