|
1 /* |
|
2 * Copyright (c) 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 "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: Implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <sip.h> |
|
19 #include <siperr.h> |
|
20 #include <sipconnection.h> |
|
21 #include <sipheaderbase.h> |
|
22 #include <sipcseqheader.h> |
|
23 #include <sipextensionheader.h> |
|
24 #include <sipresponseelements.h> |
|
25 #include <sipservertransaction.h> |
|
26 #include <sipmanagedprofileregistry.h> |
|
27 #include <sipprofileregistry.h> |
|
28 |
|
29 #include <sipheaderlookup.h> |
|
30 |
|
31 #include "TesterConstants.h" |
|
32 #include "tcuid.h" |
|
33 #include "TcLog.h" |
|
34 #include "CTcFileHandler.h" |
|
35 #include "ErrorHandling.h" |
|
36 |
|
37 #include "CTcSIPProfileContainer.h" |
|
38 #include "CTcSIPConnectionContainer.h" |
|
39 #include "CTcSIPHttpDigestContainer.h" |
|
40 #include "CTcSIPClientDiscoveryContainer.h" |
|
41 #include "CTcSIPContext.h" |
|
42 #include "SIPConstants.h" |
|
43 #include "TTcSIPCommandBase.h" |
|
44 #include "TTcSIPReceived.h" |
|
45 #include "CTTcSIPFactory.h" |
|
46 #include "CTcSIPIMSAuthenticator.h" |
|
47 #include <sipclientresolverconfigcrkeys.h> |
|
48 |
|
49 #include "CommandIndex.h" |
|
50 |
|
51 CTcSIPContext* CTcSIPContext::NewLC( CTcCTRLCodec& aCodec, |
|
52 TInt aIAPId, |
|
53 TBool aIsMandatory ) |
|
54 { |
|
55 CTcSIPContext* self = new( ELeave ) CTcSIPContext( aCodec ); |
|
56 |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL( aIAPId, aIsMandatory ); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 CTcSIPContext::~CTcSIPContext() |
|
64 { |
|
65 TcLog::Write( _L8("CTcSIPContext::~CTcSIPContext() start\n") ); |
|
66 |
|
67 iSipClientSimulator.Close(); |
|
68 |
|
69 delete iFileHandler; |
|
70 |
|
71 delete iIMSAuthenticator; |
|
72 |
|
73 iFreezer->Remove( iTimerEntry ); |
|
74 delete iFreezer; |
|
75 |
|
76 // Must be deleted before deleting transactions (in registry) |
|
77 delete iSipConnection; |
|
78 |
|
79 // We have to delete SIP Profiles before deleting |
|
80 // ManagedProfileRegistry instance. |
|
81 iRegistry.DestroyAll(); |
|
82 |
|
83 delete iSipClientDiscovery; |
|
84 delete iSipHttpDigest; |
|
85 delete iSipProfile; |
|
86 SIPHeaderLookup::Close(); |
|
87 delete iSip; |
|
88 delete iIapManager; |
|
89 delete iCenRep; |
|
90 TcLog::Write( _L8("CTcSIPContext::~CTcSIPContext() end\n") ); |
|
91 } |
|
92 |
|
93 CTcSIPContext::CTcSIPContext( CTcCTRLCodec& aCodec ) |
|
94 : CTcContextBase( aCodec ), iIsMandatory( EFalse ), iSipClientDiscovery( 0 ) |
|
95 { |
|
96 } |
|
97 |
|
98 void CTcSIPContext::ConstructL( TInt aIAPId, TBool aIsMandatory ) |
|
99 { |
|
100 iIAPId = aIAPId; |
|
101 iIsMandatory = aIsMandatory; |
|
102 |
|
103 TcLog::Write( _L8("CTcSIPContext::ConstructL() start\n") ); |
|
104 iIapManager = CTcIAPManager::NewL(); |
|
105 |
|
106 iFileHandler = CTcFileHandler::NewL(); |
|
107 |
|
108 iFreezer = CDeltaTimer::NewL( CActive::EPriorityStandard ); |
|
109 |
|
110 if ( !iIsMandatory ) |
|
111 { |
|
112 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP client\n") ); |
|
113 iSip = CSIP::NewL( TUid::Uid( TCUID ), *this ); |
|
114 iSipConnection = CTcSIPConnectionContainer::NewL( *this, IAPNameL( aIAPId ) ); |
|
115 SIPHeaderLookup::OpenL(); |
|
116 |
|
117 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP Profiles client\n") ); |
|
118 iSipProfile = CTcSIPProfileContainer::NewL( *this, *iSip ); |
|
119 |
|
120 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP Http Digest\n") ); |
|
121 iSipHttpDigest = CTcSIPHttpDigestContainer::NewL( *this, *iSip ); |
|
122 } |
|
123 |
|
124 User::LeaveIfError( iSipClientSimulator.Connect() ); |
|
125 |
|
126 iCenRep = CRepository::NewL( KCRUidSIPClientResolverConfig ); |
|
127 |
|
128 TcLog::Write( _L8("CTcSIPContext::ConstructL() end\n") ); |
|
129 } |
|
130 |
|
131 // -- CTcContextBase functions ------------------------------------------------ |
|
132 |
|
133 TTcCommandBase* CTcSIPContext::CreateCommandL( TTcIdentifier& aId, |
|
134 MTcTestContext& aContext ) |
|
135 { |
|
136 // Use base class to actually create commands. Just provide the command |
|
137 // array and its size. |
|
138 return CTcContextBase::CreateCommandL( KTcSIPCommands, |
|
139 sizeof( KTcSIPCommands ), |
|
140 aId, aContext ); |
|
141 } |
|
142 |
|
143 // -- MSIPObserver functions -------------------------------------------------- |
|
144 |
|
145 // Note that adding an object by-reference to the registry does NOT transfer |
|
146 // ownership. Adding by-pointer does transfer ownership, however. |
|
147 // Most/all SIP objects should be in the registry at this stage anyway, |
|
148 // just make sure that's the case. |
|
149 |
|
150 void CTcSIPContext::IncomingRequest( TUint32 aIapId, |
|
151 CSIPServerTransaction* aTransaction ) |
|
152 { |
|
153 TRAPD( err, { |
|
154 iRegistry.AddObjectL( aTransaction ); |
|
155 TTcSIPReceived received; |
|
156 received.Set( aIapId ); |
|
157 received.Set( aTransaction ); |
|
158 iSipConnection->QueueReceivedL( received ); |
|
159 } ) |
|
160 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
161 } |
|
162 |
|
163 void CTcSIPContext::TimedOut( CSIPServerTransaction& aSIPServerTransaction ) |
|
164 { |
|
165 TRAPD( err, { |
|
166 iRegistry.AddObjectL( aSIPServerTransaction ); |
|
167 TTcSIPReceived received; |
|
168 received.Set( &aSIPServerTransaction ); |
|
169 received.SetError( KErrTimedOut ); |
|
170 iSipConnection->QueueReceivedL( received ); |
|
171 } ) |
|
172 __ASSERT_ALWAYS( !err, Panic( KSIPErrOOMInNotifier ) ); |
|
173 } |
|
174 |
|
175 // |
|
176 // -- Internal utility functions ---------------------------------------------- |
|
177 // |
|
178 TBool CTcSIPContext::GetMandatoryValue( void ) const |
|
179 { |
|
180 return iIsMandatory; |
|
181 } |
|
182 |
|
183 void CTcSIPContext::CreateSipStack( void ) |
|
184 { |
|
185 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP client\n") ); |
|
186 iSip = CSIP::NewL( TUid::Uid( TCUID ), *this ); |
|
187 iSipConnection = CTcSIPConnectionContainer::NewL( *this, IAPNameL( iIAPId ) ); |
|
188 SIPHeaderLookup::OpenL(); |
|
189 |
|
190 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP Profiles client\n") ); |
|
191 iSipProfile = CTcSIPProfileContainer::NewL( *this, *iSip ); |
|
192 |
|
193 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP Http Digest\n") ); |
|
194 iSipHttpDigest = CTcSIPHttpDigestContainer::NewL( *this, *iSip ); |
|
195 } |
|
196 |
|
197 CTcSIPConnectionContainer* CTcSIPContext::CreateSipStack( const TDesC8& aName ) |
|
198 { |
|
199 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP client\n") ); |
|
200 iSip = CSIP::NewL( TUid::Uid( TCUID ), *this ); |
|
201 iSipConnection = CTcSIPConnectionContainer::NewL( *this, aName); |
|
202 SIPHeaderLookup::OpenL(); |
|
203 |
|
204 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP Profiles client\n") ); |
|
205 iSipProfile = CTcSIPProfileContainer::NewL( *this, *iSip ); |
|
206 |
|
207 TcLog::Write( _L8("CTcSIPContext::ConstructL() initializing SIP Http Digest\n") ); |
|
208 iSipHttpDigest = CTcSIPHttpDigestContainer::NewL( *this, *iSip ); |
|
209 |
|
210 return iSipConnection; |
|
211 } |
|
212 |
|
213 CTcSIPHttpDigestContainer& CTcSIPContext::DigestContainerL() |
|
214 { |
|
215 __ASSERT_ALWAYS( iSipHttpDigest, User::Leave( KErrNotFound ) ); |
|
216 return *iSipHttpDigest; |
|
217 } |
|
218 |
|
219 void CTcSIPContext::RemoveDigestContainer() |
|
220 { |
|
221 delete iSipHttpDigest; |
|
222 iSipHttpDigest = NULL; |
|
223 } |
|
224 |
|
225 void CTcSIPContext::CreateClientDiscoveryL( TUid aUid ) |
|
226 { |
|
227 __ASSERT_ALWAYS( !iSipClientDiscovery, User::Leave( KErrAlreadyExists ) ); |
|
228 #ifdef RD_SIP_TESTER |
|
229 iSipClientDiscovery = CTcSIPClientDiscoveryContainer::NewL( *this, aUid ); |
|
230 #else |
|
231 aUid.iUid; // Avoid compiler warning |
|
232 #endif // RD_SIP_TESTER |
|
233 } |
|
234 |
|
235 void CTcSIPContext::RemoveClientDiscovery() |
|
236 { |
|
237 #ifdef RD_SIP_TESTER |
|
238 delete iSipClientDiscovery; |
|
239 iSipClientDiscovery = 0; |
|
240 #endif // RD_SIP_TESTER |
|
241 } |
|
242 |
|
243 CTcSIPClientDiscoveryContainer& CTcSIPContext::ClientDiscoveryL() |
|
244 { |
|
245 __ASSERT_ALWAYS( iSipClientDiscovery, User::Leave( KErrNotFound ) ); |
|
246 return *iSipClientDiscovery; |
|
247 } |
|
248 |
|
249 void CTcSIPContext::IssueFreezeL( TInt aFreezeTimeSeconds ) |
|
250 { |
|
251 if ( iFreezer->IsActive() ) |
|
252 { |
|
253 User::Leave( KErrInUse ); |
|
254 } |
|
255 |
|
256 iFreezeTimeSeconds = aFreezeTimeSeconds; |
|
257 TCallBack callback( Freeze, &iFreezeTimeSeconds ); |
|
258 iTimerEntry.Set( callback ); |
|
259 iFreezer->Queue( KFreezeAfterTimer * KSecondAsMicros, iTimerEntry ); |
|
260 } |
|
261 |
|
262 TInt CTcSIPContext::Freeze( TAny* aAny ) |
|
263 { |
|
264 TInt freezeTime = *static_cast< TInt* >( aAny ); |
|
265 User::After( freezeTime * KSecondAsMicros ); |
|
266 return KErrNone; |
|
267 } |
|
268 |
|
269 CTcSIPIMSAuthenticationParams& CTcSIPContext::AuthenticateL( const TDesC8& aNonce ) |
|
270 { |
|
271 if ( !iIMSAuthenticator ) |
|
272 { |
|
273 iIMSAuthenticator = CTcSIPIMSAuthenticator::NewL(); |
|
274 } |
|
275 return iIMSAuthenticator->AuthenticateL( aNonce ); |
|
276 } |
|
277 |
|
278 const TDesC8& CTcSIPContext::SIPErrorToText( TInt aError ) |
|
279 { |
|
280 switch( aError ) |
|
281 { |
|
282 case KErrSIPMalformedMessage: |
|
283 { |
|
284 return KSIPMalformedMessageErrMsg; |
|
285 } |
|
286 case KErrSIPInvalidRegistrarResponse: |
|
287 { |
|
288 return KSIPRegistrarRespondedWithDifferentAORErrMsg; |
|
289 } |
|
290 case KErrSIPRequestPending: |
|
291 { |
|
292 return KSIPRequestPendingErrMsg; |
|
293 } |
|
294 case KErrSIPInvalidTransactionState: |
|
295 { |
|
296 return KSIPInvalidTransactionStateErrMsg; |
|
297 } |
|
298 case KErrSIPInvalidDialogState: |
|
299 { |
|
300 return KSIPInvalidDialogStateErrMsg; |
|
301 } |
|
302 case KErrSIPInvalidDialogResponse: |
|
303 { |
|
304 return KSIPInvalidResponseInDialogsErrMsg; |
|
305 } |
|
306 case KErrSIPInvalidDialogRequest: |
|
307 { |
|
308 return KSIPInvalidRequestInDialogsErrMsg; |
|
309 } |
|
310 case KErrSIPTransportFailure: |
|
311 { |
|
312 return KSIPTransportFailureErrMsg; |
|
313 } |
|
314 case KErrSIPNoAckReceived: |
|
315 { |
|
316 return KSIPNoAckReceivedErrMsg; |
|
317 } |
|
318 case KErrSIPInvalidRegistrationState: |
|
319 { |
|
320 return KSIPInvalidRegistrationStateErrMsg; |
|
321 } |
|
322 case KErrSIPInvalidContact: |
|
323 { |
|
324 return KSIPInvalidContactErrMsg; |
|
325 } |
|
326 case KErrSIPResourceNotAvailable: |
|
327 { |
|
328 return KSIPResourceNotAvailableErrMsg; |
|
329 } |
|
330 case KErrSIPResolvingFailure: |
|
331 { |
|
332 return KSIPResolvingFailureErrMsg; |
|
333 } |
|
334 case KErrSIPForbidden: |
|
335 { |
|
336 return KSIPForbiddenErrMsg; |
|
337 } |
|
338 case KErrSIPMaxCompartmentsInUse: |
|
339 { |
|
340 return KSIPMaxCompartmentsInUseErrMsg; |
|
341 } |
|
342 case KErrSIPTerminatedWithResponse: |
|
343 { |
|
344 return KSIPTerminatedWithResponseErrMsg; |
|
345 } |
|
346 case KErrSIPOutboundProxyNotResponding: |
|
347 { |
|
348 return KSIPOutboundProxyNotRespondingErrMsg; |
|
349 } |
|
350 case KSIPErrInviteCanceled: |
|
351 { |
|
352 return KSIPInviteCanceledErrMsg; |
|
353 } |
|
354 default: |
|
355 { |
|
356 return KSIPUnrecognizedErrMsg; |
|
357 } |
|
358 } |
|
359 } |
|
360 |
|
361 RSipClientSimulator& CTcSIPContext::SipClientSimulator() |
|
362 { |
|
363 return iSipClientSimulator; |
|
364 } |
|
365 |
|
366 CRepository& CTcSIPContext::Repository() |
|
367 { |
|
368 return *iCenRep; |
|
369 } |
|
370 |