|
1 /* |
|
2 * Copyright (c) 2002-2004 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 the License "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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "HttpClientApp.h" |
|
22 #include "HttpClientAppInstance.h" |
|
23 #include "HttpDownload.h" |
|
24 #include "HttpConnHandler.h" |
|
25 #include "HttpDownloadManagerServerEngine.h" |
|
26 #include "FileExt.h" |
|
27 #include "HttpDownloadMgrLogger.h" |
|
28 |
|
29 #include <in_sock.h> |
|
30 #include <CommDbConnPref.h> |
|
31 #include <HttpFilterAuthenticationInterface.h> |
|
32 #include <uaproffilter_interface.h> |
|
33 #include <HttpFilterCommonStringsExt.h> |
|
34 #include <cdblen.h> |
|
35 //#include <DeflateFilterInterface.h> |
|
36 #include <CookieFilterInterface.h> |
|
37 |
|
38 // EXTERNAL DATA STRUCTURES |
|
39 //extern ?external_data; |
|
40 |
|
41 // EXTERNAL FUNCTION PROTOTYPES |
|
42 //extern ?external_function( ?arg_type,?arg_type ); |
|
43 |
|
44 // CONSTANTS |
|
45 const TInt KShutDownTimer = 60*1000000; //60 sec - Updated to 60 secs as part of error fix JSIN-7JSE6H |
|
46 |
|
47 // MACROS |
|
48 //#define ?macro ?macro_def |
|
49 |
|
50 // LOCAL CONSTANTS AND MACROS |
|
51 //const ?type ?constant_var = ?constant; |
|
52 //#define ?macro_name ?macro_def |
|
53 |
|
54 // MODULE DATA STRUCTURES |
|
55 //enum ?declaration |
|
56 //typedef ?declaration |
|
57 |
|
58 // LOCAL FUNCTION PROTOTYPES |
|
59 //?type ?function_name( ?arg_type, ?arg_type ); |
|
60 |
|
61 // FORWARD DECLARATIONS |
|
62 //class ?FORWARD_CLASSNAME; |
|
63 |
|
64 // ============================ MEMBER FUNCTIONS =============================== |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CHttpConnShutdownTimer::NewL |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 CHttpConnShutdownTimer* CHttpConnShutdownTimer::NewL( MShutdownObserver* aObserver ) |
|
71 { |
|
72 CHttpConnShutdownTimer* self = new (ELeave) CHttpConnShutdownTimer( aObserver ); |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL(); |
|
75 CleanupStack::Pop( self ); // self |
|
76 return self; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CHttpConnShutdownTimer::CHttpConnShutdownTimer |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 CHttpConnShutdownTimer::CHttpConnShutdownTimer( MShutdownObserver* aObserver ) |
|
84 :CActive( EPriorityStandard ) |
|
85 ,iObserver( aObserver ) |
|
86 { |
|
87 CLOG_WRITE_1( "Shutdown_timer(0x%x)", this); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CHttpConnShutdownTimer::~CHttpConnShutdownTimer |
|
92 // --------------------------------------------------------- |
|
93 // |
|
94 CHttpConnShutdownTimer::~CHttpConnShutdownTimer() |
|
95 { |
|
96 Cancel(); |
|
97 iTimer.Close(); |
|
98 CLOG_WRITE_1( "Shutdown destroyed (0x%x)", this); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------- |
|
102 // CHttpConnShutdownTimer::ConstructL |
|
103 // --------------------------------------------------------- |
|
104 // |
|
105 void CHttpConnShutdownTimer::ConstructL() |
|
106 { |
|
107 User::LeaveIfError( iTimer.CreateLocal() ); |
|
108 CActiveScheduler::Add( this ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------- |
|
112 // CHttpConnShutdownTimer::Start |
|
113 // --------------------------------------------------------- |
|
114 // |
|
115 void CHttpConnShutdownTimer::Start( TInt aTimeOut ) |
|
116 { |
|
117 CLOG_WRITE("Shutdown timer started"); |
|
118 if( IsActive() ) |
|
119 { |
|
120 return; |
|
121 } |
|
122 |
|
123 iTimer.After( iStatus, aTimeOut ); |
|
124 SetActive(); |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------- |
|
128 // CHttpConnShutdownTimer::DoCancel |
|
129 // --------------------------------------------------------- |
|
130 // |
|
131 void CHttpConnShutdownTimer::DoCancel() |
|
132 { |
|
133 iTimer.Cancel(); |
|
134 CLOG_WRITE("Shutdown timer canceled"); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------- |
|
138 // CHttpConnShutdownTimer::RunL |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 void CHttpConnShutdownTimer::RunL() |
|
142 { |
|
143 LOGGER_ENTERFN("CHttpConnShutdownTimer::RunL()"); |
|
144 iObserver->ShutDown(); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CHttpConnStageNotifier::CHttpConnStageNotifier |
|
149 // C++ default constructor can NOT contain any code, that |
|
150 // might leave. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 CHttpConnStageNotifier::CHttpConnStageNotifier( CHttpConnHandler* aConnHandler ) |
|
154 :CActive( EPriorityStandard ) |
|
155 ,iConnHandler( aConnHandler ) |
|
156 { |
|
157 CLOG_WRITE_1( "Stage notifier created (0x%x)", this ); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CHttpConnStageNotifier::ConstructL |
|
162 // Symbian 2nd phase constructor can leave. |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CHttpConnStageNotifier::ConstructL() |
|
166 { |
|
167 CActiveScheduler::Add( this ); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CHttpConnStageNotifier::NewL |
|
172 // Two-phased constructor. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 CHttpConnStageNotifier* |
|
176 CHttpConnStageNotifier::NewL( CHttpConnHandler* aConnHandler ) |
|
177 { |
|
178 CHttpConnStageNotifier* self = |
|
179 new( ELeave ) CHttpConnStageNotifier( aConnHandler ); |
|
180 |
|
181 CleanupStack::PushL( self ); |
|
182 self->ConstructL(); |
|
183 CleanupStack::Pop(); |
|
184 |
|
185 return self; |
|
186 } |
|
187 |
|
188 |
|
189 // Destructor |
|
190 CHttpConnStageNotifier::~CHttpConnStageNotifier() |
|
191 { |
|
192 Cancel(); |
|
193 |
|
194 CLOG_WRITE_1( "Stage notifier destroy: (0x%x)", this ); |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CHttpConnStageNotifier::Start |
|
199 // ?implementation_description |
|
200 // (other items were commented in a header). |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 void CHttpConnStageNotifier::Start() |
|
204 { |
|
205 LOGGER_ENTERFN( "Start" ); |
|
206 |
|
207 if( IsActive() ) |
|
208 // Already observed |
|
209 { |
|
210 return; |
|
211 } |
|
212 |
|
213 iConnHandler->Connection().ProgressNotification( iProgressBuf, iStatus ); |
|
214 SetActive(); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CHttpConnHandler::DoCancel |
|
219 // ?implementation_description |
|
220 // (other items were commented in a header). |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CHttpConnStageNotifier::DoCancel() |
|
224 { |
|
225 if( iConnHandler->Connection().SubSessionHandle() ) |
|
226 { |
|
227 iConnHandler->Connection().CancelProgressNotification(); |
|
228 } |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CHttpConnHandler::RunL |
|
233 // ?implementation_description |
|
234 // (other items were commented in a header). |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CHttpConnStageNotifier::RunL() |
|
238 { |
|
239 if( iStatus == KErrNone ) |
|
240 { |
|
241 TInt stage = iProgressBuf().iStage; |
|
242 |
|
243 iConnHandler->ConnectionStageChanged( stage ); |
|
244 |
|
245 if( stage > KConnectionUninitialised ) |
|
246 // connection is still alive |
|
247 { |
|
248 iConnHandler->Connection().ProgressNotification( iProgressBuf, iStatus ); |
|
249 SetActive(); |
|
250 } |
|
251 } |
|
252 else |
|
253 { |
|
254 iConnHandler->ConnectionError( iStatus.Int() ); |
|
255 } |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CHttpConnHandler::CHttpConnHandler |
|
260 // C++ default constructor can NOT contain any code, that |
|
261 // might leave. |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 CHttpConnHandler::CHttpConnHandler( CHttpClientApp* aClientApp ) |
|
265 : CActive( EPriorityStandard ) |
|
266 , iClientApp( aClientApp ) |
|
267 { |
|
268 CLOG_CREATE; |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CHttpConnHandler::ConstructL |
|
273 // Symbian 2nd phase constructor can leave. |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CHttpConnHandler::ConstructL() |
|
277 { |
|
278 CLOG_NAME_2( _L("CHttpConnHandler_%x_c%x"), iClientApp->AppUid(), (TInt)this ); |
|
279 LOGGER_ENTERFN( "ConstructL" ); |
|
280 |
|
281 CActiveScheduler::Add( this ); |
|
282 |
|
283 iConnNotif = CHttpConnStageNotifier::NewL( this ); |
|
284 CLOG_ATTACH( iConnNotif, this ); |
|
285 iShutDown = CHttpConnShutdownTimer::NewL( this ); |
|
286 CLOG_ATTACH( iShutDown, this ); |
|
287 |
|
288 iHttpSession.OpenL(); |
|
289 CLOG_WRITE8( "Session open" ); |
|
290 InitSessionL(); |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CHttpConnHandler::NewL |
|
295 // Two-phased constructor. |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 CHttpConnHandler* CHttpConnHandler::NewL( CHttpClientApp* aClientApp ) |
|
299 { |
|
300 CHttpConnHandler* self = new( ELeave ) CHttpConnHandler( aClientApp ); |
|
301 |
|
302 CleanupStack::PushL( self ); |
|
303 self->ConstructL(); |
|
304 CleanupStack::Pop(); |
|
305 |
|
306 return self; |
|
307 } |
|
308 |
|
309 |
|
310 // Destructor |
|
311 CHttpConnHandler::~CHttpConnHandler() |
|
312 { |
|
313 if( IsActive() ) |
|
314 { |
|
315 Cancel(); |
|
316 } |
|
317 |
|
318 ShutDown( ETrue ); |
|
319 |
|
320 iHttpSession.Close(); |
|
321 |
|
322 delete iConnNotif; |
|
323 delete iShutDown; |
|
324 |
|
325 CLOG_CLOSE; |
|
326 } |
|
327 |
|
328 |
|
329 // ----------------------------------------------------------------------------- |
|
330 // CHttpConnHandler::ConnectL |
|
331 // ?implementation_description |
|
332 // (other items were commented in a header). |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 void CHttpConnHandler::ConnectL() |
|
336 { |
|
337 LOGGER_ENTERFN( "ConnectL" ); |
|
338 |
|
339 TBool doComplete( ETrue ); |
|
340 |
|
341 iShutDown->Cancel(); |
|
342 |
|
343 if( !iConnection.SubSessionHandle() ) |
|
344 // only the first connection request does this initialization |
|
345 { |
|
346 CLOG_WRITE( "No subsession" ); |
|
347 // forget the previous notifier |
|
348 if( iConnName ) |
|
349 { |
|
350 CLOG_WRITE_1("ConnName set: [%S]", iConnName); |
|
351 |
|
352 TName connName; |
|
353 |
|
354 connName.Copy( *iConnName ); |
|
355 |
|
356 User::LeaveIfError( iConnection.Open( iClientApp->Engine()->SocketServ(), connName ) ); |
|
357 |
|
358 CLOG_WRITE( "connection open" ); |
|
359 |
|
360 TNifProgress progress; |
|
361 |
|
362 iConnection.Progress( progress ); |
|
363 |
|
364 iConnStage = progress.iStage; |
|
365 CLOG_WRITE_1("Stage: %d", iConnStage); |
|
366 |
|
367 UpdateIapId(); |
|
368 } |
|
369 else |
|
370 { |
|
371 User::LeaveIfError( iConnection.Open( iClientApp->Engine()->SocketServ() ) ); |
|
372 CLOG_WRITE8_1( "Start: %d", iIapId ); |
|
373 if( iIapId ) |
|
374 { |
|
375 iPref.SetDialogPreference( ECommDbDialogPrefDoNotPrompt ); |
|
376 iPref.SetIapId( iIapId ); |
|
377 } |
|
378 else |
|
379 { |
|
380 iPref.SetDialogPreference( ECommDbDialogPrefPrompt ); |
|
381 } |
|
382 |
|
383 iConnection.Start( iPref, iStatus ); |
|
384 |
|
385 // RConnection will complete us. |
|
386 doComplete = EFalse; |
|
387 } |
|
388 |
|
389 iConnNotif->Start(); |
|
390 |
|
391 iNewConnection = ETrue; |
|
392 } |
|
393 |
|
394 CLOG_WRITE_1( "stage: %d", iConnStage ); |
|
395 if( !IsActive() ) |
|
396 { |
|
397 CLOG_WRITE( "Not active" ); |
|
398 |
|
399 SetActive(); |
|
400 |
|
401 CLOG_WRITE_1( "doComplete: %d", doComplete ); |
|
402 if( doComplete ) |
|
403 { |
|
404 TRequestStatus* dummy = &iStatus; |
|
405 |
|
406 User::RequestComplete( dummy, KErrNone ); |
|
407 } |
|
408 } |
|
409 } |
|
410 |
|
411 // ----------------------------------------------------------------------------- |
|
412 // CHttpConnHandler::Disconnect |
|
413 // ?implementation_description |
|
414 // (other items were commented in a header). |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 void CHttpConnHandler::Disconnect( TBool aAtOnce, CHttpDownload* aDownload ) |
|
418 { |
|
419 LOGGER_ENTERFN( "Disconnect()" ); |
|
420 CLOG_WRITE8_1( "Exit: %d", aAtOnce ); |
|
421 |
|
422 // to remove this download from the referenced ones |
|
423 if( aDownload ) |
|
424 { |
|
425 aDownload->SetConnHandler( NULL ); |
|
426 } |
|
427 |
|
428 TInt refs = Referencies(); |
|
429 |
|
430 CLOG_WRITE8_1( "aAtOnce: %d", aAtOnce ); |
|
431 CLOG_WRITE8_1( "refs: %d", refs ); |
|
432 |
|
433 if( aAtOnce || (!refs && !iConnName) ) |
|
434 // no more reference to this connection -> real disconnect |
|
435 // but only if the connection name was not set from outside |
|
436 // In that case only CHttpClientAppInstance::Disconnect can |
|
437 // disconnect (it uses aAtOnce ETrue). |
|
438 { |
|
439 CLOG_WRITE_1( "conn handle: %d", iConnection.SubSessionHandle() ); |
|
440 CLOG_WRITE_1( "stage: %d", iConnStage ); |
|
441 |
|
442 if( !aAtOnce |
|
443 && iConnection.SubSessionHandle() |
|
444 && iConnStage == KLinkLayerOpen ) |
|
445 { |
|
446 CLOG_WRITE_1( "ShutDown->Start: atOnce=%d", aAtOnce ); |
|
447 iShutDown->Start( KShutDownTimer ); |
|
448 } |
|
449 else |
|
450 { |
|
451 ShutDown(); |
|
452 } |
|
453 } |
|
454 } |
|
455 |
|
456 // ----------------------------------------------------------------------------- |
|
457 // CHttpConnHandler::IapId |
|
458 // ?implementation_description |
|
459 // (other items were commented in a header). |
|
460 // ----------------------------------------------------------------------------- |
|
461 // |
|
462 TUint32 CHttpConnHandler::IapId() const |
|
463 { |
|
464 return iIapId; |
|
465 } |
|
466 |
|
467 // ----------------------------------------------------------------------------- |
|
468 // CHttpConnHandler::ClientAppInst |
|
469 // ?implementation_description |
|
470 // (other items were commented in a header). |
|
471 // ----------------------------------------------------------------------------- |
|
472 // |
|
473 CHttpClientApp* CHttpConnHandler::ClientApp() const |
|
474 { |
|
475 return iClientApp; |
|
476 } |
|
477 |
|
478 // ----------------------------------------------------------------------------- |
|
479 // CHttpConnHandler::ClientAppInst |
|
480 // ?implementation_description |
|
481 // (other items were commented in a header). |
|
482 // ----------------------------------------------------------------------------- |
|
483 // |
|
484 CHttpClientAppInstance* CHttpConnHandler::ClientAppInst() const |
|
485 { |
|
486 return iClientInst; |
|
487 } |
|
488 |
|
489 // ----------------------------------------------------------------------------- |
|
490 // CHttpConnHandler::Session |
|
491 // ?implementation_description |
|
492 // (other items were commented in a header). |
|
493 // ----------------------------------------------------------------------------- |
|
494 // |
|
495 RHTTPSession& CHttpConnHandler::Session() |
|
496 { |
|
497 return iHttpSession; |
|
498 } |
|
499 |
|
500 // ----------------------------------------------------------------------------- |
|
501 // CHttpConnHandler::Connection |
|
502 // ?implementation_description |
|
503 // (other items were commented in a header). |
|
504 // ----------------------------------------------------------------------------- |
|
505 // |
|
506 RConnection& CHttpConnHandler::Connection() |
|
507 { |
|
508 return iConnection; |
|
509 } |
|
510 |
|
511 // ----------------------------------------------------------------------------- |
|
512 // CHttpConnHandler::ConnectionNameL |
|
513 // ?implementation_description |
|
514 // (other items were commented in a header). |
|
515 // ----------------------------------------------------------------------------- |
|
516 // |
|
517 HBufC* CHttpConnHandler::ConnectionNameL( TBool& aDelete ) |
|
518 { |
|
519 if( iConnName ) |
|
520 { |
|
521 aDelete = EFalse; |
|
522 return iConnName; |
|
523 } |
|
524 else if( iConnection.SubSessionHandle() ) |
|
525 { |
|
526 TName connName; |
|
527 |
|
528 aDelete = ETrue; |
|
529 |
|
530 iConnection.Name( connName ); |
|
531 |
|
532 return connName.AllocL(); |
|
533 } |
|
534 |
|
535 aDelete = EFalse; |
|
536 return NULL; |
|
537 } |
|
538 |
|
539 // ----------------------------------------------------------------------------- |
|
540 // CHttpConnHandler::APNameL |
|
541 // ?implementation_description |
|
542 // (other items were commented in a header). |
|
543 // ----------------------------------------------------------------------------- |
|
544 // |
|
545 void CHttpConnHandler::APNameL( TPtrC16& aValue ) |
|
546 { |
|
547 // TODO: APNameL |
|
548 /* |
|
549 if( iConnection.SubSessionHandle() ) |
|
550 { |
|
551 TBuf<KCommsDbSvrMaxFieldLength> name; |
|
552 TBuf<20> query; |
|
553 |
|
554 query.Format( _L("%s\\%s"), IAP, COMMDB_NAME ); |
|
555 iConnection.GetDesSetting( query, name ); |
|
556 } |
|
557 */ |
|
558 aValue.Set( KNullDesC ); |
|
559 } |
|
560 |
|
561 // ----------------------------------------------------------------------------- |
|
562 // CHttpConnHandler::IsConnected |
|
563 // ?implementation_description |
|
564 // (other items were commented in a header). |
|
565 // ----------------------------------------------------------------------------- |
|
566 // |
|
567 TBool CHttpConnHandler::IsConnected() |
|
568 { |
|
569 return iConnStage == KLinkLayerOpen; |
|
570 } |
|
571 |
|
572 // ----------------------------------------------------------------------------- |
|
573 // CHttpConnHandler::SetClientAppInst |
|
574 // ?implementation_description |
|
575 // (other items were commented in a header). |
|
576 // ----------------------------------------------------------------------------- |
|
577 // |
|
578 void CHttpConnHandler::SetClientAppInst( CHttpClientAppInstance* aClientInst ) |
|
579 { |
|
580 iClientInst = aClientInst; |
|
581 } |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // CHttpConnHandler::SetIapId |
|
585 // ?implementation_description |
|
586 // (other items were commented in a header). |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 void CHttpConnHandler::SetIapId( TUint32 aIapId ) |
|
590 { |
|
591 CLOG_WRITE8_1( "SetIAPId: %d", aIapId ); |
|
592 __ASSERT_DEBUG( !IsConnected() || (IsConnected() && aIapId == iIapId), DMPanic( KErrInUse ) ); |
|
593 |
|
594 if( IsConnected() ) |
|
595 // Do not use this new IAP id as long as connected |
|
596 { |
|
597 return; |
|
598 } |
|
599 |
|
600 iIapId = aIapId; |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // CHttpConnHandler::SetConnectionNameL |
|
605 // ?implementation_description |
|
606 // (other items were commented in a header). |
|
607 // ----------------------------------------------------------------------------- |
|
608 // |
|
609 void CHttpConnHandler::SetConnectionNameL( const TDesC& aConnName ) |
|
610 { |
|
611 CLOG_WRITE_1( "connName: %S", &aConnName ); |
|
612 |
|
613 if( !IsConnected() ) |
|
614 { |
|
615 if( aConnName.Length() ) |
|
616 { |
|
617 if( !iConnName ) |
|
618 { |
|
619 iConnName = HBufC::NewL( KMaxName ); |
|
620 } |
|
621 |
|
622 iConnName->Des().Copy( aConnName ); |
|
623 |
|
624 ConnectL(); |
|
625 } |
|
626 else |
|
627 // forget the connection name |
|
628 { |
|
629 delete iConnName; iConnName = NULL; |
|
630 } |
|
631 } |
|
632 else |
|
633 { |
|
634 CLOG_WRITE( "Connected!!!" ); |
|
635 User::Leave( KErrInUse ); |
|
636 } |
|
637 } |
|
638 |
|
639 // ----------------------------------------------------------------------------- |
|
640 // CHttpConnHandler::DoCancel |
|
641 // ?implementation_description |
|
642 // (other items were commented in a header). |
|
643 // ----------------------------------------------------------------------------- |
|
644 // |
|
645 void CHttpConnHandler::DoCancel() |
|
646 { |
|
647 LOGGER_ENTERFN( "DoCancel" ); |
|
648 |
|
649 CArrayPtrFlat<CHttpDownload>* downloads = |
|
650 iClientApp->Downloads(); |
|
651 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
652 { |
|
653 if( (*downloads)[i]->ConnHandler() == this ) |
|
654 { |
|
655 (*downloads)[i]->ConnectionFailed( KErrCancel ); |
|
656 } |
|
657 } |
|
658 } |
|
659 |
|
660 // ----------------------------------------------------------------------------- |
|
661 // CHttpConnHandler::RunL |
|
662 // ?implementation_description |
|
663 // (other items were commented in a header). |
|
664 // ----------------------------------------------------------------------------- |
|
665 // |
|
666 void CHttpConnHandler::RunL() |
|
667 { |
|
668 LOGGER_ENTERFN( "RunL()" ); |
|
669 CLOG_WRITE8_1( "%d", iStatus.Int() ); |
|
670 if( iStatus.Int() != KErrNone ) |
|
671 { |
|
672 iNewConnection = EFalse; |
|
673 |
|
674 CArrayPtrFlat<CHttpDownload>* downloads = |
|
675 iClientApp->Downloads(); |
|
676 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
677 { |
|
678 if( (*downloads)[i]->ConnHandler() == this ) |
|
679 { |
|
680 (*downloads)[i]->ConnectionFailed( iStatus.Int() ); |
|
681 } |
|
682 } |
|
683 } |
|
684 else |
|
685 { |
|
686 // Have to check the connection stage if the it was cloned. |
|
687 TNifProgress progress; |
|
688 |
|
689 iConnection.Progress( progress ); |
|
690 |
|
691 iConnStage = progress.iStage; |
|
692 CLOG_WRITE_1( "Stage: %d", iConnStage ); |
|
693 |
|
694 if( iConnStage == KLinkLayerOpen ) |
|
695 // Connect request was issued by download when connection was already |
|
696 // open -> RConnection.Start() wasn't called, only the request |
|
697 // was completed. |
|
698 { |
|
699 Connected(); |
|
700 } |
|
701 } |
|
702 } |
|
703 |
|
704 // ----------------------------------------------------------------------------- |
|
705 // CHttpConnHandler::ConnectionStageChanged |
|
706 // ?implementation_description |
|
707 // (other items were commented in a header). |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 void CHttpConnHandler::ConnectionStageChanged( TInt aStage ) |
|
711 { |
|
712 CLOG_WRITE8_1( "Stage: %d", aStage ); |
|
713 |
|
714 iConnStage = aStage; |
|
715 |
|
716 if( iConnStage == KConnectionUninitialised || |
|
717 iConnStage == KDataTransferTemporarilyBlocked |
|
718 ) |
|
719 { |
|
720 __ASSERT_DEBUG( iClientApp, DMPanic( KErrCorrupt ) ); |
|
721 CArrayPtrFlat<CHttpDownload>* downloads = |
|
722 iClientApp->Downloads(); |
|
723 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
724 { |
|
725 if( (*downloads)[i]->ConnHandler() == this ) |
|
726 { |
|
727 if( iConnStage == KConnectionUninitialised ) |
|
728 { |
|
729 // from now on this name is invalid -> forget it! |
|
730 delete iConnName; iConnName = NULL; |
|
731 |
|
732 (*downloads)[i]->Disconnected(); |
|
733 } |
|
734 else |
|
735 { |
|
736 (*downloads)[i]->Suspended(); |
|
737 } |
|
738 } |
|
739 } |
|
740 |
|
741 if( iConnStage == KConnectionUninitialised ) |
|
742 { |
|
743 ShutDown(); |
|
744 } |
|
745 if ( iConnStage == KDataTransferTemporarilyBlocked ) |
|
746 { |
|
747 iShutDown->Start( KShutDownTimer ); |
|
748 } |
|
749 } |
|
750 else if( iConnStage == KLinkLayerOpen ) |
|
751 // connection open |
|
752 { |
|
753 Connected(); |
|
754 } |
|
755 } |
|
756 |
|
757 // ----------------------------------------------------------------------------- |
|
758 // CHttpConnHandler::ConnectionError |
|
759 // ?implementation_description |
|
760 // (other items were commented in a header). |
|
761 // ----------------------------------------------------------------------------- |
|
762 // |
|
763 void CHttpConnHandler::ConnectionError( TInt aError ) |
|
764 { |
|
765 __ASSERT_DEBUG( iClientApp, DMPanic( KErrCorrupt ) ); |
|
766 CArrayPtrFlat<CHttpDownload>* downloads = |
|
767 iClientApp->Downloads(); |
|
768 |
|
769 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
770 { |
|
771 if( (*downloads)[i]->ConnHandler() == this ) |
|
772 { |
|
773 (*downloads)[i]->ConnectionFailed( aError ); |
|
774 } |
|
775 } |
|
776 } |
|
777 |
|
778 // ----------------------------------------------------------------------------- |
|
779 // CHttpConnHandler::ShutDown |
|
780 // |
|
781 // Connection notification is not canceled here, because need to know |
|
782 // when the connection is really closed. Forget the connection name, set by |
|
783 // the client app only if the connection is really closed. |
|
784 // ----------------------------------------------------------------------------- |
|
785 // |
|
786 void CHttpConnHandler::ShutDown( TBool aFromDestructor ) |
|
787 { |
|
788 CLOG_WRITE( "ShutDown" ); |
|
789 CLOG_WRITE8_1( "dest: %d", aFromDestructor ); |
|
790 |
|
791 iNewConnection = EFalse; |
|
792 |
|
793 if( iShutDown ) |
|
794 { |
|
795 iShutDown->Cancel(); |
|
796 } |
|
797 |
|
798 if( iConnNotif ) |
|
799 { |
|
800 iConnNotif->Cancel(); |
|
801 } |
|
802 |
|
803 Cancel(); |
|
804 CLOG_WRITE( "Canceled" ); |
|
805 iConnStage = KConnectionUninitialised; |
|
806 |
|
807 CLOG_WRITE( "Closing connection" ); |
|
808 iConnection.Close(); |
|
809 CLOG_WRITE( "Conn closed" ); |
|
810 |
|
811 // Pause the downloads |
|
812 CArrayPtrFlat<CHttpDownload>* downloads = |
|
813 iClientApp->Downloads(); |
|
814 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
815 { |
|
816 if( (*downloads)[i]->ConnHandler() == this ) |
|
817 { |
|
818 TRAP_IGNORE( (*downloads)[i]->PauseL( ETrue ) ); |
|
819 } |
|
820 } |
|
821 if( !iClientInst && !aFromDestructor ) |
|
822 // Client instance already exited and all download disconnected -> |
|
823 // no need for this connhandler anymore. |
|
824 // the next client will create a new connhandler and assigned downloads |
|
825 // will use that one. |
|
826 { |
|
827 CLOG_WRITE( "Destroy me" ); |
|
828 // DO NOT USE 'this' after this call!!! |
|
829 iClientApp->DestroyConnHandler( this ); |
|
830 } |
|
831 } |
|
832 |
|
833 // ----------------------------------------------------------------------------- |
|
834 // CHttpConnHandler::InitSessionL |
|
835 // ?implementation_description |
|
836 // (other items were commented in a header). |
|
837 // ----------------------------------------------------------------------------- |
|
838 // |
|
839 void CHttpConnHandler::InitSessionL() |
|
840 { |
|
841 LOGGER_ENTERFN( "InitSessionL" ); |
|
842 |
|
843 iHttpSession.StringPool().OpenL(HttpFilterCommonStringsExt::GetTable()); |
|
844 |
|
845 // Set the disconnect notification |
|
846 iHttpSession.ConnectionInfo().SetPropertyL |
|
847 ( |
|
848 iHttpSession.StringPool().StringF( HTTP::ENotifyOnDisconnect, RHTTPSession::GetTable() ), |
|
849 iHttpSession.StringPool().StringF( HTTP::EEnableDisconnectNotification, RHTTPSession::GetTable() ) |
|
850 ); |
|
851 |
|
852 CHttpFilterAuthenticationInterface::InstallFilterL(iHttpSession, ETrue); |
|
853 CHttpFilterAuthenticationInterface::InstallFilterL(iHttpSession, EFalse); |
|
854 CHttpUAProfFilterInterface::InstallFilterL(iHttpSession); |
|
855 CHttpCookieFilter::InstallFilterL(iHttpSession); |
|
856 } |
|
857 |
|
858 // ----------------------------------------------------------------------------- |
|
859 // CHttpConnHandler::SetConnectionInfoL |
|
860 // ?implementation_description |
|
861 // (other items were commented in a header). |
|
862 // ----------------------------------------------------------------------------- |
|
863 // |
|
864 void CHttpConnHandler::SetConnectionInfoL() |
|
865 { |
|
866 RStringPool strPool = iHttpSession.StringPool(); |
|
867 |
|
868 // Remove first session properties just in case. |
|
869 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
870 |
|
871 // Clear RConnection and Socket Server instances |
|
872 connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketServ,RHTTPSession::GetTable())); |
|
873 connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketConnection,RHTTPSession::GetTable())); |
|
874 |
|
875 // Clear the proxy settings |
|
876 // THTTPHdrVal proxyUsage(strPool.StringF(HTTP::EUseProxy,RHTTPSession::GetTable())); |
|
877 connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyUsage,RHTTPSession::GetTable())); |
|
878 connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyAddress,RHTTPSession::GetTable())); |
|
879 |
|
880 // RConnection and Socket Server |
|
881 connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketServ, |
|
882 RHTTPSession::GetTable()), |
|
883 THTTPHdrVal (iClientApp->Engine()->SocketServ().Handle()) ); |
|
884 |
|
885 TInt connPtr1 = REINTERPRET_CAST(TInt, &iConnection); |
|
886 connInfo.SetPropertyL ( strPool.StringF(HTTP::EHttpSocketConnection, |
|
887 RHTTPSession::GetTable() ), THTTPHdrVal (connPtr1) ); |
|
888 } |
|
889 |
|
890 // ----------------------------------------------------------------------------- |
|
891 // CHttpConnHandler::Connected |
|
892 // ?implementation_description |
|
893 // (other items were commented in a header). |
|
894 // ----------------------------------------------------------------------------- |
|
895 // |
|
896 void CHttpConnHandler::Connected() |
|
897 { |
|
898 if( iNewConnection ) |
|
899 { |
|
900 iNewConnection = EFalse; |
|
901 |
|
902 if( iStatus.Int() == KErrNone ) |
|
903 { |
|
904 if( !iIapId ) |
|
905 { |
|
906 UpdateIapId(); |
|
907 } |
|
908 |
|
909 TRAP_IGNORE( SetConnectionInfoL() ); |
|
910 } |
|
911 } |
|
912 |
|
913 __ASSERT_DEBUG( iClientApp, DMPanic( KErrCorrupt ) ); |
|
914 CArrayPtrFlat<CHttpDownload>* downloads = |
|
915 iClientApp->Downloads(); |
|
916 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
917 { |
|
918 if( (*downloads)[i]->ConnHandler() == this ) |
|
919 { |
|
920 iShutDown->Cancel(); |
|
921 (*downloads)[i]->Connected(); |
|
922 } |
|
923 } |
|
924 } |
|
925 |
|
926 // ----------------------------------------------------------------------------- |
|
927 // CHttpConnHandler::Referencies |
|
928 // ?implementation_description |
|
929 // (other items were commented in a header). |
|
930 // ----------------------------------------------------------------------------- |
|
931 // |
|
932 TInt CHttpConnHandler::Referencies() |
|
933 { |
|
934 TInt refs( 0 ); |
|
935 |
|
936 __ASSERT_DEBUG( iClientApp, DMPanic( KErrCorrupt ) ); |
|
937 CArrayPtrFlat<CHttpDownload>* downloads = |
|
938 iClientApp->Downloads(); |
|
939 |
|
940 for( TInt i = 0; i < downloads->Count(); ++i ) |
|
941 { |
|
942 if( (*downloads)[i]->ConnHandler() == this ) |
|
943 { |
|
944 ++refs; |
|
945 } |
|
946 } |
|
947 |
|
948 return refs; |
|
949 } |
|
950 |
|
951 // ----------------------------------------------------------------------------- |
|
952 // CHttpConnHandler::UpdateIapId |
|
953 // ?implementation_description |
|
954 // (other items were commented in a header). |
|
955 // ----------------------------------------------------------------------------- |
|
956 // |
|
957 void CHttpConnHandler::UpdateIapId() |
|
958 { |
|
959 if( IsConnected() ) |
|
960 { |
|
961 // 20 = it's more than enough for the format string |
|
962 TBuf<20> query; |
|
963 |
|
964 query.Format( _L("%s\\%s"), IAP, COMMDB_ID ); |
|
965 iConnection.GetIntSetting( query, iIapId ); |
|
966 } |
|
967 } |
|
968 |
|
969 // End of File |