|
1 /* |
|
2 * Copyright (c) 2006 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: See class definition below. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CTcSIPHttpDigestContainer.h" |
|
19 #include "CTcSIPContext.h" |
|
20 #include "CTcSIPConnectionContainer.h" |
|
21 #include "SipConstants.h" |
|
22 #include "ErrorHandling.h" |
|
23 #include "SIPRefresh.h" |
|
24 |
|
25 const TInt KReceivedChallengesQueueGranularity = 4; |
|
26 |
|
27 CTcSIPHttpDigestContainer* CTcSIPHttpDigestContainer::NewL( |
|
28 CTcSIPContext& aContext, |
|
29 CSIP& aSip ) |
|
30 { |
|
31 CTcSIPHttpDigestContainer* self = |
|
32 new ( ELeave ) CTcSIPHttpDigestContainer( aContext ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL( aSip ); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CTcSIPHttpDigestContainer::~CTcSIPHttpDigestContainer() |
|
40 { |
|
41 delete iSipHttpDigest; |
|
42 delete iTimer; |
|
43 iReceivedChallengesQueue.ResetAndDestroy(); |
|
44 } |
|
45 |
|
46 |
|
47 CTcSIPHttpDigestContainer::CTcSIPHttpDigestContainer( CTcSIPContext& aContext ) |
|
48 : iContext( aContext ), |
|
49 iReceivedChallengesQueue( KReceivedChallengesQueueGranularity ) |
|
50 { |
|
51 } |
|
52 |
|
53 void CTcSIPHttpDigestContainer::ConstructL( CSIP& aSip ) |
|
54 { |
|
55 iTimer = CDeltaTimer::NewL( CActive::EPriorityStandard ); |
|
56 TCallBack cb( ReceiveTimeout, this ); |
|
57 iReceiveTimeout.Set( cb ); |
|
58 |
|
59 iSipHttpDigest = CSIPHttpDigest::NewL( |
|
60 aSip, static_cast< MSIPHttpDigestChallengeObserver& >( *this ) ); |
|
61 } |
|
62 |
|
63 void CTcSIPHttpDigestContainer::ChallengeReceived( const TDesC8& aRealm ) |
|
64 { |
|
65 TRAPD( err, QueueReceivedChallengeL( aRealm ) ); |
|
66 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
67 } |
|
68 |
|
69 void CTcSIPHttpDigestContainer::ChallengeReceived( |
|
70 const CSIPClientTransaction& aTransaction ) |
|
71 { |
|
72 iContext.Connection().IncomingResponse( |
|
73 const_cast< CSIPClientTransaction& >( aTransaction ) ); |
|
74 } |
|
75 |
|
76 void CTcSIPHttpDigestContainer::ChallengeReceived( |
|
77 const CSIPRefresh& aRefresh ) |
|
78 { |
|
79 TRAPD( err, { |
|
80 iContext.Registry().AddObjectL( aRefresh ); |
|
81 TTcSIPReceived received; |
|
82 received.Set( &aRefresh ); |
|
83 received.SetEvent( TTcSIPReceived::EIncomingResponse ); |
|
84 iContext.Connection().QueueReceivedL( received ); |
|
85 } ) |
|
86 |
|
87 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
88 } |
|
89 |
|
90 HBufC8* CTcSIPHttpDigestContainer::ReceivedChallengeL( TInt aTimeout ) |
|
91 { |
|
92 if( iReceivedChallengesQueue.Count() == 0 ) |
|
93 { |
|
94 // wait for items to arrive |
|
95 iTimer->Queue( aTimeout * KSecondAsMicros, iReceiveTimeout ); |
|
96 iActiveWait.Start(); |
|
97 } |
|
98 |
|
99 // Is the queue still empty ? (i.e. timeout occurred) |
|
100 if( iReceivedChallengesQueue.Count() == 0 ) |
|
101 { |
|
102 User::Leave( KErrTimedOut ); |
|
103 } |
|
104 |
|
105 HBufC8* challenge = iReceivedChallengesQueue[ 0 ]; |
|
106 iReceivedChallengesQueue.Remove( 0 ); |
|
107 iReceivedChallengesQueue.Compress(); |
|
108 |
|
109 return challenge; |
|
110 } |
|
111 |
|
112 void CTcSIPHttpDigestContainer::QueueReceivedChallengeL( const TDesC8& aRealm ) |
|
113 { |
|
114 HBufC8* realm = aRealm.AllocLC(); |
|
115 User::LeaveIfError( iReceivedChallengesQueue.Append( realm ) ); |
|
116 CleanupStack::Pop(); //realm |
|
117 |
|
118 if( iActiveWait.IsStarted() ) |
|
119 { |
|
120 iTimer->Remove( iReceiveTimeout ); |
|
121 iActiveWait.AsyncStop(); |
|
122 } |
|
123 } |
|
124 |
|
125 TInt CTcSIPHttpDigestContainer::ReceiveTimeout( TAny* aSelf ) |
|
126 { |
|
127 CTcSIPHttpDigestContainer& self = |
|
128 *reinterpret_cast< CTcSIPHttpDigestContainer* >( aSelf ); |
|
129 if( self.iActiveWait.IsStarted() ) |
|
130 { |
|
131 self.iActiveWait.AsyncStop(); |
|
132 } |
|
133 |
|
134 return KErrNone; |
|
135 } |