|
1 /* |
|
2 * Copyright (c) 2008 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: Implements generic HTTP GET and POST functionality |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <http.h> |
|
21 #include <cookiefilterinterface.h> |
|
22 #include <uaproffilter_interface.h> |
|
23 #include "wmdrmdladefaulthttpmanager.h" |
|
24 |
|
25 #define _LOGGING_FILE L"wmdrmdladefaulthttpplugin.txt" |
|
26 #include "logfn.h" |
|
27 |
|
28 /** |
|
29 * HTTP_STRING macro |
|
30 * To use HTTP_STRING macro you need a variable 'pool' defined (of |
|
31 * RStringPool type). |
|
32 * @param aStringId - an ID for string from HTTP Client's string table |
|
33 * (e.g. 'HTTP::EAccept') |
|
34 */ |
|
35 #define HTTP_STRING(aStringId)pool.StringF(aStringId, RHTTPSession::GetTable()) |
|
36 |
|
37 /** |
|
38 * SET_HTTP_PROPERTY macro |
|
39 * Sets value for a property of HTTP session |
|
40 * @param info - RHTTPConnectionInfo |
|
41 * @param pool - RStringPool |
|
42 * @param property - property ID, a value from HTTP string table |
|
43 * @param value - value to set |
|
44 */ |
|
45 #define SET_HTTP_PROPERTY(info, pool, property, value) \ |
|
46 info.SetPropertyL( HTTP_STRING(property), THTTPHdrVal(value)) |
|
47 |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CWmDrmDlaDefaultHttpManager::NewL |
|
53 // ---------------------------------------------------------------------------- |
|
54 CWmDrmDlaDefaultHttpManager* CWmDrmDlaDefaultHttpManager::NewL( |
|
55 MWmDrmDlaDefaltHttpManagerObserver& aObserver ) |
|
56 { |
|
57 LOGFN( "CWmDrmDlaDefaultHttpManager::NewL(1)" ); |
|
58 CWmDrmDlaDefaultHttpManager* self = |
|
59 new(ELeave) CWmDrmDlaDefaultHttpManager( aObserver, 0 ); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CWmDrmDlaDefaultHttpManager::NewL |
|
68 // ---------------------------------------------------------------------------- |
|
69 CWmDrmDlaDefaultHttpManager* CWmDrmDlaDefaultHttpManager::NewL( |
|
70 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
|
71 TUint32 aIapNumber ) |
|
72 { |
|
73 LOGFN( "CWmDrmDlaDefaultHttpManager::NewL(2)" ); |
|
74 CWmDrmDlaDefaultHttpManager* self = |
|
75 new(ELeave) CWmDrmDlaDefaultHttpManager( aObserver, aIapNumber ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop( self ); |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ---------------------------------------------------------------------------- |
|
83 // CWmDrmDlaDefaultHttpManager::~CWmDrmDlaDefaultHttpManager |
|
84 // ---------------------------------------------------------------------------- |
|
85 CWmDrmDlaDefaultHttpManager::~CWmDrmDlaDefaultHttpManager() |
|
86 { |
|
87 LOGFN( "CWmDrmDlaDefaultHttpManager::~CWmDrmDlaDefaultHttpManager" ); |
|
88 Stop(); |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CpHttpManager::Get |
|
93 // ---------------------------------------------------------------------------- |
|
94 void CWmDrmDlaDefaultHttpManager::Get( |
|
95 const TDesC8& aUrl, |
|
96 const RArray<CWmDrmDlaDefaultHttpManager::THeader>& aHeaders) |
|
97 { |
|
98 LOGFN( "CWmDrmDlaDefaultHttpManager::Get" ); |
|
99 // Disallow clients to call this method before it has completed asynch |
|
100 // request |
|
101 ASSERT( !iTransactionOpen ); |
|
102 |
|
103 iOperation = EGet; |
|
104 iDataSupplier = NULL; |
|
105 |
|
106 TRAPD( err, DoStartL( aUrl, aHeaders ) ); |
|
107 if ( err ) |
|
108 { |
|
109 HandleDownloadComplete( err ); |
|
110 } |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CpHttpManager::Post |
|
115 // ---------------------------------------------------------------------------- |
|
116 void CWmDrmDlaDefaultHttpManager::Post( |
|
117 const TDesC8& aUrl, |
|
118 const RArray<CWmDrmDlaDefaultHttpManager::THeader>& aHeaders, |
|
119 MHTTPDataSupplier* aDataSupplier ) |
|
120 { |
|
121 LOGFN( "CWmDrmDlaDefaultHttpManager::Post" ); |
|
122 // Disallow clients to call this method before it has completed asynch |
|
123 // request |
|
124 ASSERT( !iTransactionOpen ); |
|
125 ASSERT( aDataSupplier ); |
|
126 |
|
127 iOperation = EPost; |
|
128 iDataSupplier = aDataSupplier; |
|
129 |
|
130 TRAPD( err, DoStartL( aUrl, aHeaders ) ); |
|
131 if ( err ) |
|
132 { |
|
133 HandleDownloadComplete( err ); |
|
134 } |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // CWmDrmDlaDefaultHttpManager::Stop |
|
139 // This method should be used instead of Cancel. |
|
140 // ---------------------------------------------------------------------------- |
|
141 void CWmDrmDlaDefaultHttpManager::Stop() |
|
142 { |
|
143 LOGFN( "CWmDrmDlaDefaultHttpManager::Stop" ); |
|
144 // Make sure Stop was not called from a callback |
|
145 ASSERT( !iInCallback ); |
|
146 |
|
147 if ( IsActive() ) |
|
148 { |
|
149 // We are still establishing the connection, cancel the active object |
|
150 Cancel(); |
|
151 } |
|
152 else |
|
153 { |
|
154 // The active object is not active - we are past the setup phase |
|
155 if ( iTransactionOpen ) |
|
156 { |
|
157 iHttpTransaction.Cancel(); |
|
158 |
|
159 // Only generate the callback if there was a transaction going on, |
|
160 // otherwise the client will get a callback without previously |
|
161 // calling StartL |
|
162 HandleDownloadComplete( KErrCancel ); |
|
163 } |
|
164 } |
|
165 |
|
166 CleanupConnection(); |
|
167 DeleteUsernamePassword(); |
|
168 iState = EConstructed; |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CWmDrmDlaDefaultHttpManager::MoreDataAvailableL |
|
173 // ---------------------------------------------------------------------------- |
|
174 void CWmDrmDlaDefaultHttpManager::MoreDataAvailableL() |
|
175 { |
|
176 LOGFN( "CWmDrmDlaDefaultHttpManager::MoreDataAvailableL" ); |
|
177 iHttpTransaction.NotifyNewRequestBodyPartL(); |
|
178 } |
|
179 |
|
180 // ---------------------------------------------------------------------------- |
|
181 // CWmDrmDlaDefaultHttpManager::SetKeepAlive |
|
182 // ---------------------------------------------------------------------------- |
|
183 void CWmDrmDlaDefaultHttpManager::SetKeepAlive( TBool aKeepAlive ) |
|
184 { |
|
185 LOGFN( "CWmDrmDlaDefaultHttpManager::SetKeepAlive" ); |
|
186 iKeepAlive = aKeepAlive; |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // CWmDrmDlaDefaultHttpManager::KeepAlive |
|
191 // ---------------------------------------------------------------------------- |
|
192 TBool CWmDrmDlaDefaultHttpManager::KeepAlive() const |
|
193 { |
|
194 LOGFN( "CWmDrmDlaDefaultHttpManager::KeepAlive" ); |
|
195 return iKeepAlive; |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // CWmDrmDlaDefaultHttpManager::GetConnectionInfoL |
|
200 // Note: TConnectionInfo& aConnectionInfo creates a PC-Lint warning to make it |
|
201 // const but aConnectionInfo is being changed after it has been put into a |
|
202 // package and GetConnectionInfo is called on the connection |
|
203 // ---------------------------------------------------------------------------- |
|
204 void CWmDrmDlaDefaultHttpManager::GetConnectionInfoL( |
|
205 TConnectionInfo& aConnectionInfo ) |
|
206 { |
|
207 LOGFN( "CWmDrmDlaDefaultHttpManager::GetConnectionInfoL" ); |
|
208 if ( (iState != EOpen) && (iState != ESubmit) ) |
|
209 { |
|
210 User::Leave( KErrNotReady ); |
|
211 } |
|
212 |
|
213 TUint count( 0 ); |
|
214 User::LeaveIfError( iConnection.EnumerateConnections( count ) ); |
|
215 |
|
216 if ( !count ) |
|
217 { |
|
218 User::Leave( KErrNotReady ); |
|
219 } |
|
220 |
|
221 TPckg<TConnectionInfo> pkg( aConnectionInfo ); |
|
222 User::LeaveIfError( iConnection.GetConnectionInfo( 1, pkg ) ); |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // CWmDrmDlaDefaultHttpManager::SetIapId |
|
227 // ---------------------------------------------------------------------------- |
|
228 void CWmDrmDlaDefaultHttpManager::SetIapId( TInt aIapId ) |
|
229 { |
|
230 LOGFN( "CWmDrmDlaDefaultHttpManager::SetIapId" ); |
|
231 iIapNumber = aIapId; |
|
232 } |
|
233 |
|
234 // ---------------------------------------------------------------------------- |
|
235 // CWmDrmDlaDefaultHttpManager::IapId |
|
236 // ---------------------------------------------------------------------------- |
|
237 TInt CWmDrmDlaDefaultHttpManager::IapId() |
|
238 { |
|
239 return iIapNumber; |
|
240 } |
|
241 |
|
242 // ============================== PRIVATE METHODS ============================== |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CWmDrmDlaDefaultHttpManager::MHFRunL |
|
246 // ---------------------------------------------------------------------------- |
|
247 void CWmDrmDlaDefaultHttpManager::MHFRunL( |
|
248 RHTTPTransaction aTransaction, |
|
249 const THTTPEvent& aEvent ) |
|
250 { |
|
251 LOGFN( "CWmDrmDlaDefaultHttpManager::MHFRunL" ); |
|
252 RHTTPResponse response; |
|
253 TPtrC8 dataChunk; |
|
254 |
|
255 // Either ESucceeded or EFailed will eventually occur |
|
256 switch ( aEvent.iStatus ) |
|
257 { |
|
258 case THTTPEvent::EGotResponseHeaders: |
|
259 response = aTransaction.Response(); |
|
260 |
|
261 iInCallback = ETrue; |
|
262 iObserver.OnResponseHeadersL( |
|
263 response, |
|
264 response.GetHeaderCollection(), |
|
265 iHttpSession.StringPool(), |
|
266 response.StatusCode() ); |
|
267 |
|
268 break; |
|
269 |
|
270 case THTTPEvent::EGotResponseBodyData: |
|
271 // A member variable is used to store the body to avoid two |
|
272 // potential problems: |
|
273 // - OnResponseBodyDataL leaves |
|
274 // - Stop is called from within OnResponseBodyDataL |
|
275 iBody = aTransaction.Response().Body(); |
|
276 User::LeaveIfNull( iBody ); |
|
277 |
|
278 iBody->GetNextDataPart( dataChunk ); |
|
279 |
|
280 iInCallback = ETrue; |
|
281 iObserver.OnResponseBodyDataL( dataChunk ); |
|
282 |
|
283 // Verify that iBody wasn't already released |
|
284 // for example by calling Stop within ResponseBodyDataL |
|
285 if ( iBody ) |
|
286 { |
|
287 iBody->ReleaseData(); |
|
288 iBody = NULL; |
|
289 } |
|
290 |
|
291 break; |
|
292 |
|
293 case THTTPEvent::ESucceeded: |
|
294 case THTTPEvent::EFailed: |
|
295 // Deal with both the same as iError will either be negative or |
|
296 // KErrNone |
|
297 // If the user cancelled the credentials dialog then make sure we |
|
298 // return KErrCancel |
|
299 HandleDownloadComplete( iCredentialsOk ? iError : KErrCancel ); |
|
300 break; |
|
301 |
|
302 default: |
|
303 // This will capture system and HTTP lib errors |
|
304 // For positive codes iError will remain to KErrNone |
|
305 if ( aEvent.iStatus < KErrNone ) |
|
306 { |
|
307 iError = aEvent.iStatus; |
|
308 } |
|
309 break; |
|
310 } |
|
311 |
|
312 iInCallback = EFalse; |
|
313 } |
|
314 |
|
315 // ---------------------------------------------------------------------------- |
|
316 // CWmDrmDlaDefaultHttpManager::MHFRunError |
|
317 // ---------------------------------------------------------------------------- |
|
318 TInt CWmDrmDlaDefaultHttpManager::MHFRunError( |
|
319 TInt aError, |
|
320 RHTTPTransaction /*aTransaction*/, |
|
321 const THTTPEvent& /*aEvent*/ ) |
|
322 { |
|
323 LOGFN( "CWmDrmDlaDefaultHttpManager::MHFRunError" ); |
|
324 HandleDownloadComplete( aError ); |
|
325 return KErrNone; |
|
326 } |
|
327 |
|
328 // ---------------------------------------------------------------------------- |
|
329 // CWmDrmDlaDefaultHttpManager::GetCredentialsL |
|
330 // This function is NOT currently used as authentication is not current used in |
|
331 // this project at the current time |
|
332 // ---------------------------------------------------------------------------- |
|
333 TBool CWmDrmDlaDefaultHttpManager::GetCredentialsL( |
|
334 const TUriC8& /*aURI*/, |
|
335 RString aRealm, |
|
336 RStringF aAuthenticationType, |
|
337 RString& aUsername, |
|
338 RString& aPassword ) |
|
339 { |
|
340 LOGFN( "CWmDrmDlaDefaultHttpManager::GetCredentialsL" ); |
|
341 iCredentialsOk = EFalse; |
|
342 RStringPool pool = aRealm.Pool(); |
|
343 if ( aAuthenticationType == HTTP_STRING( HTTP::EBasic ) ) |
|
344 { |
|
345 DeleteUsernamePassword(); |
|
346 |
|
347 // Get the username/password |
|
348 iInCallback = ETrue; |
|
349 iCredentialsOk = |
|
350 iObserver.OnGetUsernamePasswordL( iUsername, iPassword ); |
|
351 iInCallback = EFalse; |
|
352 |
|
353 // authentication = iCredentialsOk && iUsername && iPassword |
|
354 // no authentication = !iCredentialsOk && !iUsername && !iPassword |
|
355 ASSERT( (iCredentialsOk && iUsername && iPassword) || |
|
356 (!iCredentialsOk && !iUsername && !iPassword ) ); |
|
357 |
|
358 if (iCredentialsOk) |
|
359 { |
|
360 aUsername = pool.OpenStringL( *iUsername ); |
|
361 aPassword = pool.OpenStringL( *iPassword ); |
|
362 } |
|
363 } |
|
364 |
|
365 // If the authentication type is not Basic, we simply return EFalse. |
|
366 return iCredentialsOk; |
|
367 } |
|
368 |
|
369 // ---------------------------------------------------------------------------- |
|
370 // CWmDrmDlaDefaultHttpManager::RunL |
|
371 // Overrides CActive::RunL |
|
372 // ---------------------------------------------------------------------------- |
|
373 void CWmDrmDlaDefaultHttpManager::RunL() |
|
374 { |
|
375 LOGFN( "CWmDrmDlaDefaultHttpManager::RunL" ); |
|
376 User::LeaveIfError( iStatus.Int() ); |
|
377 |
|
378 switch (iState) |
|
379 { |
|
380 case EStart: |
|
381 InitializeL(); |
|
382 break; |
|
383 case EInitialize: |
|
384 Open(); |
|
385 break; |
|
386 case EOpen: |
|
387 SubmitL(); |
|
388 break; |
|
389 default: |
|
390 // Panic if called while in ESubmit |
|
391 ASSERT( 0 ); |
|
392 break; |
|
393 } |
|
394 |
|
395 // Do not advance the state if the transaction was submitted |
|
396 // MHFRunL will be called by the HTTP stack while the transaction |
|
397 // progresses |
|
398 if ( iState != ESubmit ) |
|
399 { |
|
400 // Go to the next state if not finished |
|
401 CompleteSelf(); |
|
402 } |
|
403 } |
|
404 |
|
405 // ---------------------------------------------------------------------------- |
|
406 // CWmDrmDlaDefaultHttpManager::DoCancel |
|
407 // Called while the state machine is still active. Possible states: |
|
408 // |
|
409 // - EStart and EInitialize: iStatus is already completed and CActive::Cancel |
|
410 // will not block |
|
411 // - ESubmit: this method won't be called since the AO is not active. |
|
412 // - EOpen: RConnection::Close will be called from CleanupTransaction, |
|
413 // which will complete the RConnection::Start asynchronous call. |
|
414 // ---------------------------------------------------------------------------- |
|
415 void CWmDrmDlaDefaultHttpManager::DoCancel() |
|
416 { |
|
417 LOGFN( "CWmDrmDlaDefaultHttpManager::DoCancel" ); |
|
418 ASSERT( iState != ESubmit ); |
|
419 |
|
420 // Cleanup and generate the callback |
|
421 HandleDownloadComplete( KErrCancel ); |
|
422 } |
|
423 |
|
424 // ---------------------------------------------------------------------------- |
|
425 // CWmDrmDlaDefaultHttpManager::RunError |
|
426 // Overrides CActive::RunError |
|
427 // ---------------------------------------------------------------------------- |
|
428 TInt CWmDrmDlaDefaultHttpManager::RunError( TInt aError ) |
|
429 { |
|
430 LOGFN( "CWmDrmDlaDefaultHttpManager::RunError" ); |
|
431 LOG2( "aError: %d", aError ); |
|
432 // Cleanup and generate the callback |
|
433 HandleDownloadComplete( aError ); |
|
434 return KErrNone; |
|
435 } |
|
436 |
|
437 // ---------------------------------------------------------------------------- |
|
438 // CpHttpManager::CWmDrmDlaDefaultHttpManager |
|
439 // ---------------------------------------------------------------------------- |
|
440 CWmDrmDlaDefaultHttpManager::CWmDrmDlaDefaultHttpManager( |
|
441 MWmDrmDlaDefaltHttpManagerObserver& aObserver, |
|
442 TUint32 aIapNumber ) : |
|
443 CActive( CActive::EPriorityStandard ), |
|
444 iObserver( aObserver ), |
|
445 iState( EConstructed ), |
|
446 iIapNumber( aIapNumber ), |
|
447 iKeepAlive( EFalse ) |
|
448 { |
|
449 LOGFN( "CWmDrmDlaDefaultHttpManager::CWmDrmDlaDefaultHttpManager" ); |
|
450 CActiveScheduler::Add( this ); |
|
451 } |
|
452 |
|
453 // ---------------------------------------------------------------------------- |
|
454 // CpHttpManager::ConstructL |
|
455 // ---------------------------------------------------------------------------- |
|
456 void CWmDrmDlaDefaultHttpManager::ConstructL() |
|
457 { |
|
458 LOGFN( "CWmDrmDlaDefaultHttpManager::ConstructL" ); |
|
459 } |
|
460 |
|
461 // ---------------------------------------------------------------------------- |
|
462 // CWmDrmDlaDefaultHttpManager::InitializeL |
|
463 // Handler for the EStart state. |
|
464 // ---------------------------------------------------------------------------- |
|
465 void CWmDrmDlaDefaultHttpManager::InitializeL() |
|
466 { |
|
467 LOGFN( "CWmDrmDlaDefaultHttpManager::InitializeL" ); |
|
468 User::LeaveIfError( iSocketServer.Connect() ); |
|
469 User::LeaveIfError( iConnection.Open( iSocketServer, KAfInet ) ); |
|
470 iState = EInitialize; |
|
471 } |
|
472 |
|
473 // ---------------------------------------------------------------------------- |
|
474 // CWmDrmDlaDefaultHttpManager::OpenL |
|
475 // Handler for the EInitialize state. |
|
476 // ---------------------------------------------------------------------------- |
|
477 void CWmDrmDlaDefaultHttpManager::Open() |
|
478 { |
|
479 LOGFN( "CWmDrmDlaDefaultHttpManager::Open" ); |
|
480 // Override dialog preferences |
|
481 // Use if IAP is provided, override the default one |
|
482 if ( iIapNumber ) |
|
483 { |
|
484 iCommDbPrefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
485 iCommDbPrefs.SetIapId( iIapNumber ); |
|
486 } |
|
487 |
|
488 // Start RConnection using specified CommDb preferences overrides |
|
489 // This is async call, thus - signal CWmDrmDlaDefaultHttpManager is active |
|
490 // (SetActive()) |
|
491 iCommDbPrefs.SetDirection( ECommDbConnectionDirectionOutgoing ); |
|
492 iConnection.Start( iCommDbPrefs, iStatus ); |
|
493 |
|
494 SetActive(); |
|
495 iState = EOpen; |
|
496 } |
|
497 |
|
498 // ---------------------------------------------------------------------------- |
|
499 // CWmDrmDlaDefaultHttpManager::SubmitL |
|
500 // Handler for the EOpen state. |
|
501 // ---------------------------------------------------------------------------- |
|
502 void CWmDrmDlaDefaultHttpManager::SubmitL() |
|
503 { |
|
504 LOGFN( "CWmDrmDlaDefaultHttpManager::SubmitL" ); |
|
505 |
|
506 TConnectionInfo info; |
|
507 GetConnectionInfoL( info ); |
|
508 iIapNumber = info.iIapId; |
|
509 |
|
510 // Open session |
|
511 iHttpSession.OpenL(); |
|
512 RStringPool pool = iHttpSession.StringPool(); |
|
513 |
|
514 // Associate HTTP session with connection |
|
515 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
516 |
|
517 // Specify socket server |
|
518 SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketServ, |
|
519 iSocketServer.Handle() ); |
|
520 // Specify connectionn to use |
|
521 TInt connPtr = reinterpret_cast<TInt>(&iConnection); |
|
522 SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketConnection, connPtr ); |
|
523 |
|
524 // Install HTTP authentication filter |
|
525 InstallAuthenticationL( iHttpSession ); |
|
526 |
|
527 CHttpCookieFilter::InstallFilterL( iHttpSession ); |
|
528 |
|
529 RHTTPFilterCollection filterColl = iHttpSession.FilterCollection(); |
|
530 filterColl.RemoveFilter( |
|
531 iHttpSession.StringPool().StringF( |
|
532 HTTP::ERedirect, RHTTPSession::GetTable() ) ); |
|
533 |
|
534 CHttpUAProfFilterInterface::InstallFilterL( iHttpSession ); |
|
535 |
|
536 // Parse URI |
|
537 TUriParser8 srcAddress; |
|
538 User::LeaveIfError( srcAddress.Parse( *iSrcAddress ) ); |
|
539 |
|
540 // Open HTTP transaction |
|
541 iHttpTransaction = iHttpSession.OpenTransactionL( srcAddress, *this, |
|
542 HTTP_STRING( (EGet == iOperation) ? HTTP::EGET : HTTP::EPOST ) ); |
|
543 iTransactionOpen = ETrue; |
|
544 |
|
545 // Set the data supplier if a POST operation |
|
546 if ( EPost == iOperation ) |
|
547 { |
|
548 iHttpTransaction.Request().SetBody( *iDataSupplier ); |
|
549 } |
|
550 |
|
551 |
|
552 TInt pos = iSrcAddress->Locate( '?' ); |
|
553 |
|
554 // If no query ('?') pos is rightmost character |
|
555 pos = (pos != KErrNotFound) ? pos : iSrcAddress->Length(); |
|
556 TPtrC8 ptrUrl = iSrcAddress->Left( pos ); |
|
557 |
|
558 // Only print if there is a ('?') and something to print after it |
|
559 if ( pos < iSrcAddress->Length() ) |
|
560 { |
|
561 TPtrC8 ptrQs = iSrcAddress->Mid( pos ); |
|
562 } |
|
563 // Set HTTP headers for the transaction |
|
564 RHTTPHeaders hdr = iHttpTransaction.Request().GetHeaderCollection(); |
|
565 TInt nofheaders = iHdrValues.Count(); |
|
566 |
|
567 for ( TInt i = 0; i < nofheaders; i++ ) |
|
568 { |
|
569 TInt field = iHdrFields[i]; |
|
570 const TDesC8& fieldStr = HTTP_STRING( field ).DesC(); |
|
571 HBufC8* pValue = iHdrValues[i]; |
|
572 SetHeaderL( hdr, field, *pValue ); |
|
573 } |
|
574 |
|
575 // Submit HTTP transaction |
|
576 // This will set in motion the HTTP download |
|
577 iHttpTransaction.SubmitL(); |
|
578 iState = ESubmit; |
|
579 } |
|
580 |
|
581 // ---------------------------------------------------------------------------- |
|
582 // CWmDrmDlaDefaultHttpManager::DoStartL |
|
583 // ---------------------------------------------------------------------------- |
|
584 void CWmDrmDlaDefaultHttpManager::DoStartL( |
|
585 const TDesC8& aUrl, |
|
586 const RArray<CWmDrmDlaDefaultHttpManager::THeader>& aHeaders ) |
|
587 { |
|
588 LOGFN( "CWmDrmDlaDefaultHttpManager::DoStartL" ); |
|
589 CleanupTransaction(); |
|
590 |
|
591 // Store callers URL |
|
592 iSrcAddress = aUrl.AllocL(); |
|
593 |
|
594 // Store headers |
|
595 TInt nofheaders = aHeaders.Count(); |
|
596 for ( TInt i = 0; i < nofheaders; i++ ) |
|
597 { |
|
598 iHdrFields.AppendL( aHeaders[i].iField ); |
|
599 iHdrValues.AppendL( aHeaders[i].iVal.AllocL() ); |
|
600 } |
|
601 |
|
602 if ( (iState == EOpen) && iKeepAlive ) |
|
603 { |
|
604 TConnectionInfo connectionInfo; |
|
605 GetConnectionInfoL(connectionInfo); |
|
606 if ( connectionInfo.iIapId != iIapNumber && |
|
607 iIapNumber != 0 && connectionInfo.iIapId != 0 ) |
|
608 { |
|
609 CleanupConnection(); |
|
610 iState = EStart; |
|
611 } |
|
612 } |
|
613 else |
|
614 { |
|
615 iState = EConstructed == iState ? EStart : EOpen; |
|
616 } |
|
617 |
|
618 iError = KErrNone; |
|
619 iCredentialsOk = ETrue; |
|
620 |
|
621 CompleteSelf(); |
|
622 } |
|
623 |
|
624 // ---------------------------------------------------------------------------- |
|
625 // CWmDrmDlaDefaultHttpManager::HandleDownloadComplete |
|
626 // Close HTTP connection and clean up instance variables. |
|
627 // |
|
628 // Must be called to complete client's request and cleanup, either on |
|
629 // successful download, or some error condition |
|
630 // ---------------------------------------------------------------------------- |
|
631 void CWmDrmDlaDefaultHttpManager::HandleDownloadComplete( TInt aError ) |
|
632 { |
|
633 LOGFN( "CWmDrmDlaDefaultHttpManager::HandleDownloadComplete" ); |
|
634 LOG2( "aError: %d", aError ); |
|
635 CleanupTransaction(); |
|
636 |
|
637 iInCallback = ETrue; |
|
638 iObserver.OnTransactionComplete( aError ); |
|
639 iInCallback = EFalse; |
|
640 |
|
641 if ( iDataSupplier ) |
|
642 { |
|
643 iDataSupplier->ReleaseData(); |
|
644 iDataSupplier = NULL; |
|
645 } |
|
646 } |
|
647 |
|
648 // ---------------------------------------------------------------------------- |
|
649 // CWmDrmDlaDefaultHttpManager::CleanupTransaction |
|
650 // ---------------------------------------------------------------------------- |
|
651 void CWmDrmDlaDefaultHttpManager::CleanupTransaction() |
|
652 { |
|
653 LOGFN( "CWmDrmDlaDefaultHttpManager::CleanupTransaction" ); |
|
654 if ( iBody ) |
|
655 { |
|
656 iBody->ReleaseData(); |
|
657 iBody = NULL; |
|
658 } |
|
659 |
|
660 // Release HTTP transaction & session resources |
|
661 delete iSrcAddress; |
|
662 iSrcAddress = NULL; |
|
663 |
|
664 TInt nofheaders = iHdrValues.Count(); |
|
665 for ( TInt i = 0; i < nofheaders; i++ ) |
|
666 { |
|
667 delete iHdrValues[i]; |
|
668 } |
|
669 |
|
670 // set to empty |
|
671 iHdrValues.Reset(); |
|
672 iHdrFields.Reset(); |
|
673 |
|
674 iHttpTransaction.Close(); |
|
675 iHttpSession.Close(); |
|
676 |
|
677 if ( !iKeepAlive ) |
|
678 { |
|
679 CleanupConnection(); |
|
680 iState = ESubmit == iState ? EConstructed : iState; |
|
681 } |
|
682 else if ( ESubmit == iState ) |
|
683 { |
|
684 // end of a transaction |
|
685 iState = EOpen; |
|
686 } |
|
687 else |
|
688 { |
|
689 // do nothing. This is to get rid of a PC-Lint warning |
|
690 } |
|
691 |
|
692 iTransactionOpen = EFalse; |
|
693 } |
|
694 |
|
695 // ---------------------------------------------------------------------------- |
|
696 // CWmDrmDlaDefaultHttpManager::CleanupConnection |
|
697 // ---------------------------------------------------------------------------- |
|
698 void CWmDrmDlaDefaultHttpManager::CleanupConnection() |
|
699 { |
|
700 LOGFN( "CWmDrmDlaDefaultHttpManager::CleanupConnection" ); |
|
701 iConnection.Close(); |
|
702 iSocketServer.Close(); |
|
703 } |
|
704 |
|
705 // ---------------------------------------------------------------------------- |
|
706 // CWmDrmDlaDefaultHttpManager::CompleteSelf |
|
707 // ---------------------------------------------------------------------------- |
|
708 void CWmDrmDlaDefaultHttpManager::CompleteSelf() |
|
709 { |
|
710 LOGFN( "CWmDrmDlaDefaultHttpManager::CompleteSelf" ); |
|
711 if ( !IsActive() ) // else already waiting |
|
712 { |
|
713 TRequestStatus* status = &iStatus; |
|
714 User::RequestComplete( status, KErrNone ); |
|
715 SetActive(); |
|
716 } |
|
717 } |
|
718 |
|
719 // ---------------------------------------------------------------------------- |
|
720 // CWmDrmDlaDefaultHttpManager::SetHeaderL |
|
721 // ---------------------------------------------------------------------------- |
|
722 void CWmDrmDlaDefaultHttpManager::SetHeaderL( |
|
723 RHTTPHeaders& aHeaders, |
|
724 TInt aHdrField, |
|
725 const TDesC8& aHdrValue ) const |
|
726 { |
|
727 RStringPool pool = iHttpSession.StringPool(); |
|
728 RStringF valStr = pool.OpenFStringL( aHdrValue ); |
|
729 CleanupClosePushL( valStr ); |
|
730 THTTPHdrVal val( valStr ); |
|
731 aHeaders.SetFieldL( HTTP_STRING( aHdrField ), val ); |
|
732 CleanupStack::PopAndDestroy( &valStr ); // Close |
|
733 } |
|
734 |
|
735 // ---------------------------------------------------------------------------- |
|
736 // CWmDrmDlaDefaultHttpManager::DeleteUsernamePassword |
|
737 // This function is NOT currently used as authentication is not current used in |
|
738 // this project at the current time |
|
739 // ---------------------------------------------------------------------------- |
|
740 void CWmDrmDlaDefaultHttpManager::DeleteUsernamePassword() |
|
741 { |
|
742 LOGFN( "CWmDrmDlaDefaultHttpManager::DeleteUsernamePassword" ); |
|
743 delete iUsername; |
|
744 iUsername = NULL; |
|
745 delete iPassword; |
|
746 iPassword = NULL; |
|
747 } |
|
748 |
|
749 // End of File |