|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // CSIPTransitionEngine definition file |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #ifndef TRANSITIONENGINE_H |
|
24 #define TRANSITIONENGINE_H |
|
25 |
|
26 |
|
27 #include <e32base.h> |
|
28 |
|
29 #include <sip.h> |
|
30 #include <sipobserver.h> |
|
31 #include <sipconnectionobserver.h> |
|
32 #include <sipprofileregistryobserver.h> |
|
33 #include <sipprofile.h> |
|
34 #include <sipprofileregistry.h> |
|
35 #include <sipfromheader.h> |
|
36 #include <siptoheader.h> |
|
37 #include <sipcontactheader.h> |
|
38 |
|
39 #include <sipmessageelements.h> |
|
40 #include <siprequestelements.h> |
|
41 #include <sipresponseelements.h> |
|
42 |
|
43 #include <siprefresh.h> |
|
44 #include <sipregistrationbinding.h> |
|
45 |
|
46 #include <sipdialog.h> |
|
47 #include <sipinvitedialogassoc.h> |
|
48 #include <sipsubscribedialogassoc.h> |
|
49 #include <sipnotifydialogassoc.h> |
|
50 #include <sipreferdialogassoc.h> |
|
51 #include <sipservertransaction.h> |
|
52 #include <sipclienttransaction.h> |
|
53 #include <sipaddress.h> |
|
54 #include <sdpdocument.h> |
|
55 #include <sipcontenttypeheader.h> |
|
56 #include <sdpcodecstringconstants.h> |
|
57 #include <sdpcodecstringpool.h> |
|
58 #include <sipstrings.h> |
|
59 #include <sipstrconsts.h> |
|
60 |
|
61 #include <sipcseqheader.h> |
|
62 #include <sipeventheader.h> |
|
63 #include <sipexpiresheader.h> |
|
64 #include <sipacceptheader.h> |
|
65 #include "siphlcommontypes.h" |
|
66 #include <siperr.h> |
|
67 |
|
68 #include <siphttpdigestchallengeobserver.h> |
|
69 #include <siphttpdigest.h> |
|
70 |
|
71 #ifdef __FLOG_ACTIVE |
|
72 // This will do the logging if logging is enabled |
|
73 #include <comms-infras/ss_log.h> |
|
74 #endif |
|
75 |
|
76 class CSipStateMachine; |
|
77 |
|
78 class MSIPRegistrationClient |
|
79 /** |
|
80 To be implemented by whoever uses CSIPTransitionEngine to Register |
|
81 at the SIP registrar - see CSIPTransitionEngine::RegisterL |
|
82 */ |
|
83 { |
|
84 public: |
|
85 |
|
86 /** |
|
87 Called by the TE when the requested registration is complete |
|
88 @param aError error indication, if KErrNone - the registration |
|
89 has been successful, non-successful otherwise. |
|
90 */ |
|
91 virtual void RegistrationComplete(TInt aError) = 0; |
|
92 |
|
93 /** |
|
94 Called by the TE when 'this' has been unregistered either as a result of: |
|
95 - previously issued deregistration request |
|
96 - unregistered by the registrar |
|
97 |
|
98 @param aError error indication |
|
99 */ |
|
100 virtual void DeRegistrationComplete(TInt aError) = 0; |
|
101 |
|
102 /** |
|
103 Called by the TE when a error occurs which has to be notified to "its" |
|
104 connection providers |
|
105 |
|
106 @param aError error indication |
|
107 */ |
|
108 virtual void ErrorOccurred(TInt aError) = 0; |
|
109 |
|
110 /** |
|
111 Called by the State Machine to flag that a peer is calling. |
|
112 |
|
113 @return the SIP profileId the TE will use to identify 'this' |
|
114 */ |
|
115 virtual TUint32 GetProfileId() = 0; |
|
116 |
|
117 /** |
|
118 Called by the TransitionEngien Manager to obtain the AppUId of the |
|
119 Conn Provider when Detaching |
|
120 |
|
121 @return the appUid stored by the ConnProvider |
|
122 */ |
|
123 virtual TUid GetAppUid() = 0; |
|
124 }; |
|
125 |
|
126 |
|
127 class CSIPTransitionEngine : public CBase, |
|
128 MSIPConnectionObserver, |
|
129 MSIPProfileRegistryObserver, |
|
130 MSIPHttpDigestChallengeObserver |
|
131 |
|
132 /** |
|
133 SIPTransitionEngine |
|
134 This class implements the following set of methods |
|
135 - Call back methods which are called by the Sip stack. These trigger transition in the State Machines |
|
136 - Call back methods which are triggered by the Profile Manager (for Registration, Profile events) |
|
137 |
|
138 @internalComponent |
|
139 @released since v9.2 |
|
140 */ |
|
141 { |
|
142 public: |
|
143 friend class CSIPTransitionEngineBundle; |
|
144 |
|
145 //New Functions - Services provided by CSIPTransitionEngine |
|
146 /** |
|
147 This method is called by a Connection Provider to initialize |
|
148 Registration |
|
149 |
|
150 @param aRegistrationClient , an object which implements MSIPRegistrationClient interface ( a SIPCPR) |
|
151 */ |
|
152 IMPORT_C void RegisterL(MSIPRegistrationClient* aConnProv); |
|
153 |
|
154 /** |
|
155 This method is called by a Connection Provider to initialize |
|
156 DeRegistration |
|
157 |
|
158 @param aRegistrationClient , an object which implements MSIPRegistrationClient interface ( a SIPCPR) |
|
159 */ |
|
160 IMPORT_C void Deregister(MSIPRegistrationClient* aConnProv); |
|
161 |
|
162 |
|
163 /** |
|
164 This method is called by a State Machine, to register itself |
|
165 with the TransitionEngine |
|
166 |
|
167 @param aStateMachine Register Instance of State machine with TE |
|
168 */ |
|
169 IMPORT_C void AddStateMachineL(CSipStateMachine* aStateMachine); |
|
170 |
|
171 |
|
172 /** |
|
173 This method is called by a Connection Provider to initialize |
|
174 Registration |
|
175 |
|
176 @return profile id of a matching profile already available with TransitionEngine |
|
177 @param aProfileId , profile id to be matached |
|
178 */ |
|
179 IMPORT_C TUint32 FindDuplicateProfile(TUint32 aProfileId); |
|
180 |
|
181 |
|
182 /** |
|
183 This method is called to add a Credentials structure to a list of credentials |
|
184 maintained by the TransitionEngine |
|
185 */ |
|
186 |
|
187 IMPORT_C void AddCredentialsL(TSIPCredentials aCredential); |
|
188 |
|
189 /** |
|
190 Returns the 'from' field associated with the given profile. |
|
191 @param aProfileId the id of the profile the 'from' field should pertain to. |
|
192 |
|
193 @return the 'from' field associated with aProfileId. Given 'this' has been |
|
194 asked to register the profile. |
|
195 */ |
|
196 IMPORT_C const TDesC8* GetFromField(TUint32 aProfileId) const; |
|
197 |
|
198 /** |
|
199 This method associates the SIP transaction with a particular State machine |
|
200 |
|
201 @param aStateMachine Instance of the state machine |
|
202 @param aTransaction which will be associated with the state machine |
|
203 */ |
|
204 void SetTransaction(CSipStateMachine* aStateMachine, CSIPTransactionBase* aTransaction); |
|
205 |
|
206 /** |
|
207 This method associates the SIP Dialog association with a particular State machine |
|
208 |
|
209 @param aStateMachine Instance of the state machine |
|
210 @param aDialoAssoc which will be associated with the state machine |
|
211 */ |
|
212 void SetDialogAssoc(CSipStateMachine* aStateMachine, CSIPDialogAssocBase* aDialoAssoc); |
|
213 |
|
214 /** |
|
215 This method will cleanup the transition engine related to a particular state machine |
|
216 |
|
217 @param aStateMachine which needs to be cleaned up |
|
218 */ |
|
219 void Cleanup(CSipStateMachine * aStateMachine); |
|
220 |
|
221 /** |
|
222 This method will find the state machine to handle the incoming call. |
|
223 */ |
|
224 CSipStateMachine* FindSMForIncomingCall(); |
|
225 |
|
226 /** |
|
227 This method will find the state machine which is associated with the particular |
|
228 transaction. |
|
229 |
|
230 @param aTransaction which needs to be matched with SM |
|
231 */ |
|
232 CSipStateMachine* FindStateMachine(CSIPTransactionBase& aTransaction); |
|
233 |
|
234 /** |
|
235 This method will find the state machine which is associated with the particular |
|
236 Dialog. |
|
237 |
|
238 @param aDialogAssoc which needs to be matched with SM |
|
239 */ |
|
240 CSipStateMachine* FindStateMachine(CSIPDialogAssocBase& aDialogAssoc); |
|
241 |
|
242 /** |
|
243 Overloaded method will find the state machine which is associated with the particular |
|
244 Dialog. |
|
245 |
|
246 @param aDialogAssoc which needs to be matched with SM |
|
247 */ |
|
248 CSipStateMachine* FindStateMachine(CSIPDialogAssocBase* aDialogAssoc); |
|
249 |
|
250 /** |
|
251 Overloaded method will find the state machine which is associated with the particular |
|
252 Dialog. |
|
253 |
|
254 @param aDialogAssoc which needs to be matched with SM |
|
255 */ |
|
256 CSipStateMachine* FindStateMachine(CSIPDialog& aDialogAssoc); |
|
257 |
|
258 /** |
|
259 Overloaded method will find the state machine which is associated with the particular |
|
260 Dialog. |
|
261 |
|
262 @param aTransaction which needs to be matched with SM |
|
263 */ |
|
264 CSipStateMachine* FindStateMachine(const CSIPTransactionBase* aTransaction); |
|
265 |
|
266 /** |
|
267 This method will return the SIP connection associated with the Transition Engine |
|
268 */ |
|
269 CSIPConnection* GetSipConnection(); |
|
270 |
|
271 /** |
|
272 This method returns the handle of the registration client associated with the |
|
273 profile Id |
|
274 |
|
275 @param aProfileId for registration association |
|
276 */ |
|
277 MSIPRegistrationClient* FindRegistrationClient(TUint32 aProfileId); |
|
278 |
|
279 /** |
|
280 This function increases the reference count |
|
281 */ |
|
282 void Attach(); |
|
283 |
|
284 /** |
|
285 This function decreases the reference count |
|
286 */ |
|
287 //todo |
|
288 TInt Detach(); |
|
289 //TInt Detach(MSIPRegistrationClient* aRegClient); |
|
290 |
|
291 /** |
|
292 This function returns an IAP id |
|
293 */ |
|
294 TInt IapId(); |
|
295 |
|
296 // Methods from base classes |
|
297 // From MSIPConnectionObserver |
|
298 /** |
|
299 A SIP request outside a dialog has been received from the network. |
|
300 |
|
301 @param aTransaction SIP server transaction. The ownership is transferred. |
|
302 */ |
|
303 void IncomingRequest( CSIPServerTransaction* aTransaction ); |
|
304 |
|
305 /** |
|
306 A SIP request within a dialog has been received |
|
307 |
|
308 @param aTransaction SIP server transaction. The ownership is transferred. |
|
309 @param aDialog the dialog that this transaction belongs to. |
|
310 */ |
|
311 void IncomingRequest( CSIPServerTransaction* aTransaction, |
|
312 CSIPDialog& aDialog ); |
|
313 |
|
314 /** |
|
315 IncomingResponse (from MSIPConnectionObserver) |
|
316 */ |
|
317 void IncomingResponse( CSIPClientTransaction& aTransaction ); |
|
318 |
|
319 /** |
|
320 A SIP response that is within a dialog association or creates a dialog association. |
|
321 |
|
322 @param aTransaction contains response elements. |
|
323 @param aDialogAssoc a dialog association. |
|
324 */ |
|
325 void IncomingResponse( CSIPClientTransaction& aTransaction, |
|
326 CSIPDialogAssocBase& aDialogAssoc ); |
|
327 |
|
328 /** |
|
329 IncomingResponse (from MSIPConnectionObserver) |
|
330 Multiple SIP responses have been received to the single INVITE due to the forking proxy. |
|
331 Note that each response creates a separate INVITE dialog association.Multiple responses |
|
332 can arrive until SIP stack completes UAC core INVITE transaction.If clients deletes INVITE |
|
333 transaction after first SIP response other possible responses will be consumed by the implementation. |
|
334 |
|
335 @param aTransaction contains response elements |
|
336 @param aDialogAssoc INVITE dialog association; |
|
337 */ |
|
338 void IncomingResponse( CSIPClientTransaction& aTransaction, |
|
339 CSIPInviteDialogAssoc* aDialogAssoc ); |
|
340 |
|
341 /** |
|
342 IncomingResponse (from MSIPConnectionObserver) |
|
343 |
|
344 @param aTransaction contains response elements |
|
345 @param aRegistration contains the Registration Binding |
|
346 */ |
|
347 void IncomingResponse( CSIPClientTransaction& aTransaction, |
|
348 CSIPRegistrationBinding& aRegistration ); |
|
349 |
|
350 /** |
|
351 An asynchronous error has occurred in the stack related to the |
|
352 request indicated by the given transaction. |
|
353 |
|
354 @param aError system wide or sip error code |
|
355 @param aTransaction failed transaction. |
|
356 @param aSIPConnection a SIP connection |
|
357 */ |
|
358 void ErrorOccured( TInt aError, CSIPTransactionBase& aTransaction ); |
|
359 |
|
360 /** |
|
361 An asynchronous error has occurred in the stack related |
|
362 to the request indicated by the given transaction. |
|
363 |
|
364 @param aError system wide or sip error code |
|
365 @param aTransaction the failed transaction. |
|
366 @param aRegistration the failed registration. |
|
367 */ |
|
368 void ErrorOccured( TInt aError, |
|
369 CSIPClientTransaction& aTransaction, |
|
370 CSIPRegistrationBinding& aRegistration ); |
|
371 |
|
372 /** |
|
373 An asynchronous error has occured related to a request within an existing dialog. |
|
374 |
|
375 @param aError system wide or sip error code |
|
376 @param aTransaction the failed transaction. |
|
377 @param aDialogAssoc the failed dialog associoation. |
|
378 */ |
|
379 void ErrorOccured( TInt aError, |
|
380 CSIPTransactionBase& aTransaction, |
|
381 CSIPDialogAssocBase& aDialogAssoc ); |
|
382 |
|
383 /** |
|
384 An asynchronous error has occured related to a refresh |
|
385 |
|
386 @param aError system wide or sip error code |
|
387 @param aSIPRefresh original refresh object. |
|
388 */ |
|
389 void ErrorOccured( TInt aError, CSIPRefresh& aSIPRefresh ); |
|
390 |
|
391 /** |
|
392 An asynchronous error has occured related to a periodical refresh |
|
393 that relates to a registration. |
|
394 |
|
395 @param aError system wide or sip error code; |
|
396 @param aRegistration associated registration. |
|
397 */ |
|
398 void ErrorOccured( TInt aError, |
|
399 CSIPRegistrationBinding& aRegistration ); |
|
400 |
|
401 /** |
|
402 An asynchronous error has occured related to a periodical refresh |
|
403 that belongs to SIP dialog association. |
|
404 |
|
405 @param aError system wide or sip error code; |
|
406 @param aDialogAssoc SIP dialog association. |
|
407 */ |
|
408 void ErrorOccured( TInt aError, |
|
409 CSIPDialogAssocBase& aDialogAssoc ); |
|
410 |
|
411 /** |
|
412 SIP stack has completed UAC core INVITE transaction 64*T1 seconds after the reception of |
|
413 the first 2xx response. No more 2xx responses can be received to the issued single INVITE. |
|
414 If the INVITE transaction does not create a dialog, or the INVITE transaction encounters |
|
415 an error, this event will not be sent. |
|
416 |
|
417 @param aTransaction a complete UAC core INVITE transaction |
|
418 */ |
|
419 void InviteCompleted( CSIPClientTransaction& aTransaction ); |
|
420 |
|
421 /** |
|
422 Invite was canceled with the CANCEL |
|
423 |
|
424 @param aTransaction a canceled INVITE UAS transaction |
|
425 */ |
|
426 void InviteCanceled( CSIPServerTransaction& aTransaction ); |
|
427 |
|
428 /** |
|
429 Connection state has changed.If connection state has changed to EInactive or EUnavailable, |
|
430 SIP stack has removed all stand-alone SIP refreshes, registrations and dialog associations |
|
431 that client requested to refresh. Client may re-issue refresh requests (stand-alone, |
|
432 registration or dialog association related) when connection becomes EActive again. |
|
433 SIP stack also terminates all pending sip client transactions and no errors are reported back |
|
434 to the client about the terminated transactions nor about removed refreshes in order to |
|
435 avoid event flood. |
|
436 |
|
437 @param aState indicates the current connection state |
|
438 */ |
|
439 void ConnectionStateChanged( CSIPConnection::TState aState ); |
|
440 |
|
441 //From MSIPProfileRegistryObserver |
|
442 /** |
|
443 An event related to SIP Profile has accorred |
|
444 |
|
445 @param aProfileId a profile Id |
|
446 @param aEvent an occurred event |
|
447 */ |
|
448 void ProfileRegistryErrorOccurred(TUint32 aProfileId, TInt aError); |
|
449 |
|
450 /** |
|
451 An asynchronous error has occurred related to SIP profile Event is send to |
|
452 those observers, who have the corresponding profile instantiated. |
|
453 |
|
454 @param aProfileId the id of failed profile |
|
455 @param aError an occurred error |
|
456 */ |
|
457 void ProfileRegistryEventOccurred(TUint32 aProfileId, TEvent aEvent); |
|
458 |
|
459 /** |
|
460 SIP request resulted in 401/407 response that contains |
|
461 a challenge. |
|
462 |
|
463 @param aRealm a realm for which the challenge was received |
|
464 */ |
|
465 void ChallengeReceived(const TDesC8& aRealm); |
|
466 |
|
467 private: |
|
468 /** |
|
469 Instantiation function will be called from a friend class |
|
470 |
|
471 @param aSip Handle to the SIP |
|
472 @param aIapId IAP on which the connection will be created |
|
473 */ |
|
474 static CSIPTransitionEngine* NewL(CSIP& aSip, TInt aIapId); |
|
475 |
|
476 /** |
|
477 constructor of the class |
|
478 */ |
|
479 CSIPTransitionEngine(CSIP& aSip, TInt aIapId); |
|
480 |
|
481 /** |
|
482 destructor of the class |
|
483 */ |
|
484 ~CSIPTransitionEngine(); |
|
485 |
|
486 /** |
|
487 2nd phase construction of the class |
|
488 |
|
489 */ |
|
490 void ConstructL(); |
|
491 |
|
492 /** |
|
493 This method handles the incoming request if it comes outside of a existing dialog |
|
494 |
|
495 @param aTransaction The transaction associated with the new dialog. |
|
496 */ |
|
497 void IncomingRequestL( CSIPServerTransaction* aTransaction ); |
|
498 |
|
499 /** |
|
500 This method handles the requests coming inside a Dialog |
|
501 |
|
502 @param aTransaction The transaction associated with the new dialog. |
|
503 @param aDialog Handle to the dialog itself |
|
504 */ |
|
505 void IncomingRequestL( CSIPServerTransaction* aTransaction, CSIPDialog& aDialog ); |
|
506 |
|
507 /** |
|
508 This method is used to walkthrough the array of credentials |
|
509 and set them once a challenge is recieved |
|
510 |
|
511 @param aRealm - Realm of the issuer of the challenge |
|
512 */ |
|
513 TBool FindAndSetCredentials(const TDesC8& aRealm); |
|
514 |
|
515 private: |
|
516 // For Logging |
|
517 __FLOG_DECLARATION_MEMBER; |
|
518 |
|
519 // The IAP id of the CSipConnection |
|
520 TUint iIapId; |
|
521 // The connection state |
|
522 CSIPConnection::TState iConnState; |
|
523 // Handle to the SIP stack |
|
524 CSIP& iSIP; |
|
525 // Handle to the SIP connection towards a particular IAP |
|
526 CSIPConnection* iConnection; |
|
527 // Handle to the SIP Profile Registry |
|
528 CSIPProfileRegistry* iProfileRegistry; |
|
529 // Handle to the wait till the Connection Starts |
|
530 CActiveSchedulerWait iActiveWait; |
|
531 // Reference count |
|
532 TInt iRefCount; |
|
533 //Digest Class Instance for Setting Credentials |
|
534 CSIPHttpDigest *iDigest; |
|
535 // Holder of Registration clients |
|
536 RPointerArray<MSIPRegistrationClient> iRegClientArray; |
|
537 // Holder of SIP profiles |
|
538 RPointerArray<CSIPProfile> iProfileArray; |
|
539 // Holder of SIP state machine |
|
540 RPointerArray<CHLStateMachine> iSMArray; |
|
541 //Holder of TSIPCredentials |
|
542 RArray<TSIPCredentials> iCredentialsArray; |
|
543 }; |
|
544 |
|
545 |
|
546 inline CSIPConnection * CSIPTransitionEngine::GetSipConnection() |
|
547 /** |
|
548 Return the CSIp connection |
|
549 */ |
|
550 { |
|
551 return iConnection; |
|
552 } |
|
553 |
|
554 inline void CSIPTransitionEngine::Attach() |
|
555 /** |
|
556 Increments the refrence count |
|
557 */ |
|
558 { |
|
559 iRefCount++; |
|
560 } |
|
561 //todo |
|
562 inline TInt CSIPTransitionEngine::Detach() |
|
563 //inline TInt CSIPTransitionEngine::Detach(MSIPRegistrationClient* aRegClient) |
|
564 /** |
|
565 Decrements the reference count |
|
566 */ |
|
567 { |
|
568 return --iRefCount; |
|
569 } |
|
570 |
|
571 inline TInt CSIPTransitionEngine::IapId() |
|
572 /** |
|
573 returns the IAP id |
|
574 */ |
|
575 { |
|
576 return iIapId; |
|
577 } |
|
578 |
|
579 |
|
580 #endif |