|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CXcapHttpTransport |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <in_iface.h> |
|
23 #include <xdmlogwriter.h> |
|
24 #include <deflatefilterinterface.h> |
|
25 #include <msgconnmanagerapi.h> |
|
26 #include "XdmCredentials.h" |
|
27 #include "XcapHttpReqGet.h" |
|
28 #include "XcapHttpReqPut.h" |
|
29 #include "XcapHttpReqMkcol.h" |
|
30 #include "XcapHttpReqHead.h" |
|
31 #include "XcapHttpRequest.h" |
|
32 #include "XcapHttpReqDelete.h" |
|
33 #include "XcapHttpTransport.h" |
|
34 #include "XcapHttpAuthManager.h" |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 // |
|
38 |
|
39 |
|
40 // ---------------------------------------------------------- |
|
41 // CXcapHttpTransport::CXcapHttpTransport |
|
42 // |
|
43 // ---------------------------------------------------------- |
|
44 // |
|
45 CXcapHttpTransport::CXcapHttpTransport( MMsgConnManager& aConnManager) : |
|
46 iCredValidity( EFalse ), |
|
47 iSessionClosed( ETrue ), |
|
48 iConnManager( aConnManager ) |
|
49 { |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------- |
|
53 // CXcapHttpTransport::NewL |
|
54 // |
|
55 // ---------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CXcapHttpTransport* CXcapHttpTransport::NewL( const TDesC& aRootUri, |
|
58 MMsgConnManager& aConnManager, |
|
59 const TXdmCredentials& aDigestCredentials ) |
|
60 { |
|
61 CXcapHttpTransport* self = new ( ELeave ) CXcapHttpTransport( aConnManager ); |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL( aRootUri, aDigestCredentials ); |
|
64 CleanupStack::Pop(); //self |
|
65 return self; |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------- |
|
69 // CXcapHttpTransport::~CXcapHttpTransport |
|
70 // |
|
71 // ---------------------------------------------------- |
|
72 // |
|
73 CXcapHttpTransport::~CXcapHttpTransport() |
|
74 { |
|
75 #ifdef _DEBUG |
|
76 WriteToLog( _L8( "CXcapHttpTransport::~CXcapHttpTransport()" ) ); |
|
77 #endif |
|
78 delete iRootUri; |
|
79 delete iAuthManager; |
|
80 iHttpSession.Close(); |
|
81 iSessionClosed = ETrue; |
|
82 delete iProxyBuffer; |
|
83 #ifdef _DEBUG |
|
84 WriteToLog( _L8( " Destructor ends." ) ); |
|
85 #endif |
|
86 delete iLogWriter; |
|
87 } |
|
88 |
|
89 // ---------------------------------------------------------- |
|
90 // CXcapHttpTransport::ConstructL |
|
91 // |
|
92 // ---------------------------------------------------------- |
|
93 // |
|
94 void CXcapHttpTransport::ConstructL( const TDesC& aRootUri, const TXdmCredentials& aDigestCredentials ) |
|
95 { |
|
96 #ifdef _DEBUG |
|
97 iLogWriter = CXdmLogWriter::NewL( KTransportLogFile ); |
|
98 WriteToLog( _L8( "CXcapHttpTransport::ConstructL" ) ); |
|
99 #endif |
|
100 SetRootUriL( aRootUri ); |
|
101 InitialiseSessionL(); |
|
102 iAuthManager = CXcapHttpAuthManager::NewL( iHttpSession, *this, aDigestCredentials ); |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------- |
|
106 // CXcapHttpTransport::SetRootUriL |
|
107 // |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 EXPORT_C void CXcapHttpTransport::SetRootUriL( const TDesC& aRootUri ) |
|
111 { |
|
112 delete iRootUri; |
|
113 iRootUri = NULL; |
|
114 iRootUri = HBufC8::NewL( aRootUri.Length() ); |
|
115 iRootUri->Des().Copy( aRootUri ); |
|
116 } |
|
117 |
|
118 // ---------------------------------------------------- |
|
119 // CXcapHttpTransport::GetL |
|
120 // |
|
121 // ---------------------------------------------------- |
|
122 // |
|
123 EXPORT_C CXcapHttpReqGet* CXcapHttpTransport::GetL( const TDesC& aRequestUri ) |
|
124 { |
|
125 #ifdef _DEBUG |
|
126 WriteToLog( _L8( "CXcapHttpTransport::GetRequestL()" ) ); |
|
127 #endif |
|
128 if( !iSessionClosed ) |
|
129 return CXcapHttpReqGet::NewL( aRequestUri, iHttpSession, *iAuthManager, *this ); |
|
130 else |
|
131 { |
|
132 User::Leave( KErrNotReady ); |
|
133 return NULL; |
|
134 } |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------- |
|
138 // CXcapHttpTransport::PutL |
|
139 // |
|
140 // ---------------------------------------------------- |
|
141 // |
|
142 EXPORT_C CXcapHttpReqPut* CXcapHttpTransport::PutL( const TDesC& aRequestUri ) |
|
143 { |
|
144 #ifdef _DEBUG |
|
145 WriteToLog( _L8( "CXcapHttpTransport::PutRequestL()" ) ); |
|
146 #endif |
|
147 if( !iSessionClosed ) |
|
148 return CXcapHttpReqPut::NewL( aRequestUri, iHttpSession, *iAuthManager, *this ); |
|
149 else |
|
150 { |
|
151 User::Leave( KErrNotReady ); |
|
152 return NULL; |
|
153 } |
|
154 } |
|
155 |
|
156 // ---------------------------------------------------- |
|
157 // CXcapHttpTransport::Mkcol |
|
158 // |
|
159 // ---------------------------------------------------- |
|
160 // |
|
161 EXPORT_C CXcapHttpReqMkcol* CXcapHttpTransport::MkcolL( const TDesC& aRequestUri ) |
|
162 { |
|
163 #ifdef _DEBUG |
|
164 WriteToLog( _L8( "CXcapHttpTransport::MkcolRequestL()" ) ); |
|
165 #endif |
|
166 if( !iSessionClosed ) |
|
167 return CXcapHttpReqMkcol::NewL( aRequestUri, iHttpSession, *iAuthManager, *this ); |
|
168 else |
|
169 { |
|
170 User::Leave( KErrNotReady ); |
|
171 return NULL; |
|
172 } |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------- |
|
176 // CXcapHttpTransport::Head |
|
177 // |
|
178 // ---------------------------------------------------- |
|
179 // |
|
180 EXPORT_C CXcapHttpReqHead* CXcapHttpTransport::HeadL( const TDesC& aRequestUri ) |
|
181 { |
|
182 #ifdef _DEBUG |
|
183 WriteToLog( _L8( "CXcapHttpTransport::HeadRequestL()" ) ); |
|
184 #endif |
|
185 if( !iSessionClosed ) |
|
186 return CXcapHttpReqHead::NewL( aRequestUri, iHttpSession, *iAuthManager, *this ); |
|
187 else |
|
188 { |
|
189 User::Leave( KErrNotReady ); |
|
190 return NULL; |
|
191 } |
|
192 } |
|
193 |
|
194 // ---------------------------------------------------- |
|
195 // CXcapHttpTransport::DeleteL |
|
196 // |
|
197 // ---------------------------------------------------- |
|
198 // |
|
199 EXPORT_C CXcapHttpReqDelete* CXcapHttpTransport::DeleteL( const TDesC& aRequestUri ) |
|
200 { |
|
201 #ifdef _DEBUG |
|
202 WriteToLog( _L8( "CXcapHttpTransport::DeleteRequestL()" ) ); |
|
203 #endif |
|
204 if( !iSessionClosed ) |
|
205 return CXcapHttpReqDelete::NewL( aRequestUri, iHttpSession, *iAuthManager, *this ); |
|
206 else |
|
207 { |
|
208 User::Leave( KErrNotReady ); |
|
209 return NULL; |
|
210 } |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------- |
|
214 // CXcapHttpTransport::RootUri |
|
215 // |
|
216 // ---------------------------------------------------------- |
|
217 // |
|
218 EXPORT_C TPtrC8 CXcapHttpTransport::RootUri() |
|
219 { |
|
220 return iRootUri != NULL ? iRootUri->Des() : TPtrC8(); |
|
221 } |
|
222 |
|
223 // ---------------------------------------------------- |
|
224 // CXcapHttpTransport::InitialiseSessionL |
|
225 // |
|
226 // ---------------------------------------------------- |
|
227 // |
|
228 void CXcapHttpTransport::InitialiseSessionL() |
|
229 { |
|
230 #ifdef _DEBUG |
|
231 WriteToLog( _L8( "CXcapHttpTransport::InitialiseSessionL()" ) ); |
|
232 #endif |
|
233 iHttpSession.OpenL(); |
|
234 RSocketServ& session = iConnManager.SocketSession(); |
|
235 RConnection& connection = iConnManager.Connection(); |
|
236 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
237 RStringPool stringPool = iHttpSession.StringPool(); |
|
238 TInt conn = reinterpret_cast <TInt> ( &connection ); |
|
239 connInfo.SetPropertyL( stringPool.StringF( HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), |
|
240 THTTPHdrVal( session.Handle() ) ); |
|
241 connInfo.SetPropertyL( stringPool.StringF( HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), |
|
242 THTTPHdrVal( conn ) ); |
|
243 connInfo.SetPropertyL( stringPool.StringF( HTTP::EHTTPVersion, RHTTPSession::GetTable() ), |
|
244 THTTPHdrVal( stringPool.StringF( HTTP::EHttp11, RHTTPSession::GetTable() ) ) ); |
|
245 connInfo.SetPropertyL( stringPool.StringF( HTTP::ESecureDialog, RHTTPSession::GetTable() ), |
|
246 THTTPHdrVal( stringPool.StringF( HTTP::EDialogPrompt, RHTTPSession::GetTable() ) ) ); |
|
247 //CHttpDeflateFilter::InstallFilterL( iHttpSession ); |
|
248 iSessionClosed = EFalse; |
|
249 #ifdef _DEBUG |
|
250 WriteToLog( _L8( "InitialiseSessionL() ends." ) ); |
|
251 #endif |
|
252 } |
|
253 |
|
254 #ifdef _DEBUG |
|
255 // ---------------------------------------------------- |
|
256 // CXcapHttpTransport::WriteToLog |
|
257 // Writes to the log, 8-bit version |
|
258 // ---------------------------------------------------- |
|
259 // |
|
260 void CXcapHttpTransport::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) const |
|
261 { |
|
262 VA_LIST list; |
|
263 VA_START( list, aFmt ); |
|
264 TBuf8<KLogBufferMaxSize> buf; |
|
265 buf.FormatList( aFmt, list ); |
|
266 iLogWriter->WriteToLog( buf ); |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------- |
|
270 // CXcapHttpTransport::WriteToLog |
|
271 // Writes to the log, 16-bit version |
|
272 // ---------------------------------------------------- |
|
273 // |
|
274 void CXcapHttpTransport::WriteToLog( TRefByValue<const TDesC> aFmt,... ) const |
|
275 { |
|
276 VA_LIST list; |
|
277 VA_START( list, aFmt ); |
|
278 TBuf<KLogBufferMaxSize> buf; |
|
279 buf.FormatList( aFmt, list ); |
|
280 iLogWriter->WriteToLog( buf ); |
|
281 } |
|
282 #endif //_DEBUG |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 // End of File |