merge with master
[framework/osp/net.git] / src / inc / FNetHttp_HttpSessionImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 /**
19  * @file                FNetHttp_HttpSessionImpl.h
20  * @brief               This is the header file for the %_HttpSessionImpl class.
21  *
22  * This header file contains the declarations of the %_HttpSessionImpl class.
23  */
24
25 #ifndef _FNET_HTTP_INTERNAL_HTTP_SESSION_IMPL_H_
26 #define _FNET_HTTP_INTERNAL_HTTP_SESSION_IMPL_H_
27
28 #include <curl.h>
29 #include <glib.h>
30 #include <FOspConfig.h>
31 #include <FNetHttpHttpTypes.h>
32
33 namespace Tizen { namespace Base
34 {
35 class String;
36 } }
37
38 namespace Tizen { namespace Net
39 {
40 class ManagedNetConnection;
41 class NetConnection;
42 class _NetConnectionImpl;
43 } }
44
45 namespace Tizen { namespace Net { namespace Http
46 {
47 class HttpSession;
48 class HttpTransaction;
49 class HttpHeader;
50 class HttpAuthentication;
51 class HttpCookieStorageManager;
52 class _HttpNetConnectionEventListenerImpl;
53 class _HttpManagedNetConnectionEventListenerImpl;
54 class _HttpHeaderImpl;
55 class _HttpMultipleConnectionInfo;
56 /**
57  * @class       _HttpSessionImpl
58  * @brief       This class represents an HTTP session.
59  *
60  * @since 2.1
61  */
62
63 class _OSP_EXPORT_ _HttpSessionImpl
64         : public Tizen::Base::Object
65 {
66
67 public:
68         /**
69          * This is the default constructor for this class.
70          *
71          * @since 2.1
72          * @remarks             After creating an instance of this class, one of the Construct() methods must be called explicitly to initialize the instance.
73          * @see                 Construct()
74          */
75         _HttpSessionImpl(HttpSession* pHttpSession);
76
77         /**
78          * @see                 HttpSession::Construct()
79          */
80         result Construct(NetHttpSessionMode sessionMode, const Tizen::Base::String* pProxyAddr, const Tizen::Base::String& hostAddr, const HttpHeader* pCommonHeader, NetHttpCookieFlag flag = NET_HTTP_COOKIE_FLAG_ALWAYS_MANUAL);
81
82         /**
83          * @see                 HttpSession::Construct()
84          */
85         result Construct(const NetConnection& netConnection, NetHttpSessionMode sessionMode, const Tizen::Base::String* pProxyAddr, const Tizen::Base::String& hostAddr, const HttpHeader* pCommonHeader, NetHttpCookieFlag flag = NET_HTTP_COOKIE_FLAG_ALWAYS_MANUAL);
86
87         /**
88          * This is the destructor for this class.
89          *
90          * @since 2.1
91          */
92         virtual ~_HttpSessionImpl(void);
93
94         /**
95          * @see                 HttpSession::OpenTransactionN()
96          */
97         HttpTransaction* OpenTransactionN(void);
98
99         /**
100         * @see                          HttpSession::OpenTransactionN()
101         */
102         HttpTransaction* OpenTransactionN(const HttpAuthentication& auth);
103
104         /**
105          * @see                 HttpSession::CancelTransaction()
106          */
107         result CancelTransaction(HttpTransaction& httpTransaction);
108
109         /**
110         * @see                          HttpSession::CloseTransaction()
111         */
112         result CloseTransaction(HttpTransaction& httpTransaction);
113
114         /**
115         * @see                          HttpSession::CloseAllTransactions()
116         */
117         result CloseAllTransactions(void);
118
119         /**
120         * @see                          HttpSession::SetAutoRedirectionEnabled()
121         */
122         result SetAutoRedirectionEnabled(bool enable);
123
124         /**
125         * @see                          HttpSession::IsAutoRedirectionEnabled()
126         */
127         bool IsAutoRedirectionEnabled(void) const;
128
129         /**
130         * @see                  HttpSession::GetActiveTransactionCount()
131         */
132         int GetActiveTransactionCount(void) const;
133
134         /**
135         * @see                  HttpSession::GetMaxTransactionCount()
136         */
137         int GetMaxTransactionCount(void) const;
138
139         /**
140         * @see                  HttpSession::GetCookieStorageManager()
141         */
142         HttpCookieStorageManager* GetCookieStorageManager(void) const;
143
144 public:
145         /**
146          * Gets the Impl instance.
147          *
148          * @since 2.1
149          * @return                      The pointer to _HttpSessionImpl
150          * @param[in]   pHttpSession            An instance of HttpSession
151          */
152         static _HttpSessionImpl* GetInstance(HttpSession& httpSession);
153
154         /**
155          * Gets the Impl instance.
156          *
157          * @since 2.1
158          * @return                      The pointer to _HttpSessionImpl
159          * @param[in]   pHttpSession            An instance of HttpSession
160          */
161         static const _HttpSessionImpl* GetInstance(const HttpSession& httpSession);
162
163 public:
164         NetHttpSessionMode GetSessionMode(void) const;
165
166         Tizen::Base::String GetHostAddress(void) const;
167
168         Tizen::Base::String* GetProxyAddress(void) const;
169
170         void SetProxyAddress(Tizen::Base::String* pProxyAddress);
171
172         Tizen::Base::String GetDeviceName(void) const;
173
174         void SetDeviceName(const Tizen::Base::String& deviceName);
175
176         bool IsSessionValid(void) const;
177
178         void SetSessionState(bool isValid);
179
180         NetHttpCookieFlag GetHttpCookieFlag(void) const;
181
182         HttpSession* GetHttpSession(void) const;
183
184         _HttpMultipleConnectionInfo* GetHttpMultipleConnectionInfo(void) const;
185
186         Tizen::Base::Collection::ArrayList* GetActiveTransactions(void);
187
188         bool IsConnectionStarted(void) const;
189
190         HttpTransaction* OpenTransactionWithCurlN(CURL* pCurl, bool uncheckedMaxTransactions = false);
191
192         HttpTransaction* ReopenTransactionWithAuthN(HttpTransaction& httpTransaction);
193
194         result Disconnect(void); // HttpSession is disconnected when network problem is occurred.
195
196         void IgnoreSslVerification(void);
197
198         result Dispose(void);
199
200         result Close(void);
201
202         static int GenerateSessionId(void);
203
204         int GetSessionId(void) const;
205
206         static result InitializeSession(void);
207
208 public:
209         _HttpSessionImpl(const _HttpSessionImpl& rhs);
210
211         _HttpSessionImpl& operator =(const _HttpSessionImpl& rhs);
212
213 private:
214         static int __generatedSessionId;
215         int __sessionId;
216         static int __countOfSessions;   //The number of opened sessions in the application.
217
218         HttpSession* __pHttpSession;
219         bool __isConstructed;
220         NetHttpSessionMode __sessionMode;
221         Tizen::Base::String* __pProxyAddress;
222         Tizen::Base::String __hostAddress;
223         HttpHeader* __pCommonHeader;
224         NetHttpCookieFlag __cookieFlag;
225         Tizen::Base::Collection::ArrayList __activeTransactions;
226         int __countOfTransaction;
227         bool __isSecure;
228         bool __isValid;
229         bool __isClosed;
230         bool __isAutoRedirectionEnabled;
231         bool __isAlreadyResumed;
232         class _HttpMultipleConnectionInfo* __pHttpMultipleConnectionInfo;
233         HttpCookieStorageManager* __pCookieStorageMgr;
234         Tizen::Net::NetConnection* __pNetConnection;
235         _HttpNetConnectionEventListenerImpl* __pNetConnectionListener;
236         Tizen::Net::ManagedNetConnection* __pManagedNetConnection;
237         _HttpManagedNetConnectionEventListenerImpl* __pManagedNetConnectionListener;
238         Tizen::Base::String __deviceName;
239
240         friend class HttpSession;
241
242 }; // _HttpSessionImpl
243
244 } } } // Tizen::Net::Http
245 #endif // _FNET_HTTP_INTERNAL_HTTP_SESSION_IMPL_H_