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 FNetHttpHttpSession.cpp
20 * @brief This is the implementation file for HttpSession class.
22 * This file contains the implementation of HttpSession class.
25 #include <unique_ptr.h>
26 #include <FBaseResult.h>
27 #include <FBaseUtilStringUtil.h>
28 #include <FNetHttpHttpSession.h>
29 #include <FBaseSysLog.h>
30 #include <FSec_AccessController.h>
31 #include "FNetHttp_HttpSessionImpl.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Base::Utility;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Security;
39 using namespace Tizen::Net;
41 namespace Tizen { namespace Net { namespace Http
44 HttpSession::HttpSession()
45 : __pHttpSessionImpl(null)
49 HttpSession::~HttpSession(void)
51 if (__pHttpSessionImpl != null)
53 delete __pHttpSessionImpl;
54 __pHttpSessionImpl = null;
59 HttpSession::Construct(NetHttpSessionMode sessionMode, const String* pProxyAddr, const String& hostAddr,
60 const HttpHeader* pCommonHeader,
61 NetHttpCookieFlag flag)
63 SysAssertf(__pHttpSessionImpl == null,
64 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
68 unique_ptr<_HttpSessionImpl> pHttpSessionImpl(new (std::nothrow) _HttpSessionImpl(this));
69 SysTryReturnResult(NID_NET_HTTP, pHttpSessionImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
71 r = pHttpSessionImpl->Construct(sessionMode, pProxyAddr, hostAddr, pCommonHeader, flag);
72 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "Propagating.");
74 __pHttpSessionImpl = pHttpSessionImpl.release();
80 HttpSession::Construct(const Tizen::Net::NetConnection& netConnection, NetHttpSessionMode sessionMode, const String* pProxyAddr,
81 const String& hostAddr, const HttpHeader* pCommonHeader,
82 NetHttpCookieFlag flag)
84 SysAssertf(__pHttpSessionImpl == null,
85 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
89 unique_ptr<_HttpSessionImpl> pHttpSessionImpl(new (std::nothrow) _HttpSessionImpl(this));
90 SysTryReturnResult(NID_NET_HTTP, pHttpSessionImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
92 r = pHttpSessionImpl->Construct(netConnection, sessionMode, pProxyAddr, hostAddr, pCommonHeader, flag);
93 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "Propagating.");
95 __pHttpSessionImpl = pHttpSessionImpl.release();
100 HttpCookieStorageManager*
101 HttpSession::GetCookieStorageManager(void) const
103 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
105 result r = E_SUCCESS;
106 HttpCookieStorageManager* pHttpCookieStorageManager = null;
108 pHttpCookieStorageManager = __pHttpSessionImpl->GetCookieStorageManager();
110 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, pHttpCookieStorageManager, r, "[%s] Propagating.", GetErrorMessage(r));
112 return pHttpCookieStorageManager;
116 HttpSession::SetAutoRedirectionEnabled(bool enable)
118 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
120 result r = E_SUCCESS;
122 r = __pHttpSessionImpl->SetAutoRedirectionEnabled(enable);
123 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "Propagating.");
129 HttpSession::IsAutoRedirectionEnabled(void) const
131 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
133 result r = E_SUCCESS;
137 rs = __pHttpSessionImpl->IsAutoRedirectionEnabled();
139 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, rs, r, "[%s] Propagating.", GetErrorMessage(r));
145 HttpSession::OpenTransactionN()
147 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
149 result r = E_SUCCESS;
150 HttpTransaction* pHttpTransaction = null;
152 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
153 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
154 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, null, r, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
156 pHttpTransaction = __pHttpSessionImpl->OpenTransactionN();
158 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, pHttpTransaction, r, "[%s] Propagating.", GetErrorMessage(r));
160 return pHttpTransaction;
165 HttpSession::OpenTransactionN(const HttpAuthentication& auth)
167 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
169 result r = E_SUCCESS;
170 HttpTransaction* pHttpTransaction = null;
172 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
173 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
174 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, null, r, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
176 pHttpTransaction = __pHttpSessionImpl->OpenTransactionN(auth);
178 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, pHttpTransaction, r, "[%s] Propagating.", GetErrorMessage(r));
180 return pHttpTransaction;
184 HttpSession::CloseAllTransactions(void)
186 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
188 result r = E_SUCCESS;
190 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
191 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
192 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "The application does not have the privilege to call this method.", GetErrorMessage(r));
194 r = __pHttpSessionImpl->CloseAllTransactions();
195 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "Propagating.");
201 HttpSession::CancelTransaction(HttpTransaction& httpTransaction)
203 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
205 result r = E_SUCCESS;
207 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
208 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
209 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
211 r = __pHttpSessionImpl->CancelTransaction(httpTransaction);
212 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "Propagating.");
218 HttpSession::CloseTransaction(HttpTransaction& httpTransaction)
220 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
222 result r = E_SUCCESS;
224 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
225 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
226 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "The application does not have the privilege to call this method.");
228 r = __pHttpSessionImpl->CloseTransaction(httpTransaction);
229 SysTryReturnResult(NID_NET_HTTP, r == E_SUCCESS, r, "Propagating.");
235 HttpSession::GetActiveTransactionCount(void) const
237 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
239 result r = E_SUCCESS;
240 int activeTransactionCount = -1;
242 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
243 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
244 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, -1, r, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
246 activeTransactionCount = __pHttpSessionImpl->GetActiveTransactionCount();
248 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, activeTransactionCount, r, "[%s] Propagating.", GetErrorMessage(r));
250 return activeTransactionCount;
254 HttpSession::GetMaxTransactionCount(void) const
256 SysAssertf(__pHttpSessionImpl != null, "Not yet constructed. Construct() should be called before use.");
258 result r = E_SUCCESS;
259 int maxTransactionCount = -1;
261 r = _AccessController::CheckUserPrivilege(_PRV_HTTP);
262 r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_OUT_OF_MEMORY);
263 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, -1, r, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(r));
265 maxTransactionCount = __pHttpSessionImpl->GetMaxTransactionCount();
268 SysTryReturn(NID_NET_HTTP, r == E_SUCCESS, maxTransactionCount, r, "[%s] Propagating.", GetErrorMessage(r));
270 return maxTransactionCount;
273 } } } // Tizen::Net::Http