|
1 |
|
2 /* |
|
3 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 * All rights reserved. |
|
5 * This component and the accompanying materials are made available |
|
6 * under the terms of "Eclipse Public License v1.0" |
|
7 * which accompanies this distribution, and is available |
|
8 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 * |
|
10 * Initial Contributors: |
|
11 * Nokia Corporation - initial contribution. |
|
12 * |
|
13 * Contributors: |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef _SIPEXSIPENGINE_H_ |
|
22 #define _SIPEXSIPENGINE_H_ |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <e32std.h> |
|
27 #include <e32math.h> |
|
28 #include <s32mem.h> |
|
29 #include <in_sock.h> |
|
30 |
|
31 #include <sip.h> |
|
32 #include <sipdialog.h> |
|
33 #include <sipobserver.h> |
|
34 #include <sipinvitedialogassoc.h> |
|
35 #include <sipconnectionobserver.h> |
|
36 #include <sipservertransaction.h> |
|
37 #include <sipmessageelements.h> |
|
38 #include <siprequestelements.h> |
|
39 |
|
40 #include <sdpdocument.h> |
|
41 #include <sdpmediafield.h> |
|
42 #include <sdporiginfield.h> |
|
43 #include <sdpconnectionfield.h> |
|
44 #include <sdpcodecstringconstants.h> |
|
45 #include <sdpcodecstringpool.h> |
|
46 |
|
47 #include <sipprofile.h> |
|
48 #include <sipprofileregistry.h> |
|
49 #include <sipprofileregistryobserver.h> |
|
50 |
|
51 #include <sipaddress.h> |
|
52 #include <sipcontenttypeheader.h> |
|
53 #include <sipfromheader.h> |
|
54 |
|
55 #include "SIPExSIPEngineObserver.h" |
|
56 |
|
57 #include "SIPExSIPIdleState.h" |
|
58 #include "SIPExSIPClientEstablishingState.h" |
|
59 #include "SIPExSIPClientOfferingState.h" |
|
60 #include "SIPExSIPServerOfferingState.h" |
|
61 #include "SIPExSIPServerEstablishingState.h" |
|
62 #include "SIPExSIPEstablishedState.h" |
|
63 #include "SIPExSIPTerminatingState.h" |
|
64 |
|
65 |
|
66 // FORWARD DECLARATIONS |
|
67 class CSIP; |
|
68 class CSIPDialog; |
|
69 class CSIPServerTransaction; |
|
70 class CSIPMessageElements; |
|
71 class CSIPRequestElements; |
|
72 |
|
73 class CSIPAddress; |
|
74 class CSIPContentTypeHeader; |
|
75 class CSIPFromHeader; |
|
76 |
|
77 class MSIPExSIPEngineObserver; |
|
78 |
|
79 class CSIPExSIPIdleState; |
|
80 class CSIPExSIPClientEstablishingState; |
|
81 class CSIPExSIPClientOfferingState; |
|
82 class CSIPExSIPServerOfferingState; |
|
83 class CSIPExSIPServerEstablishingState; |
|
84 class CSIPExSIPEstablishedState; |
|
85 class CSIPExSIPTerminatingState; |
|
86 |
|
87 |
|
88 // CLASS DECLARATION |
|
89 |
|
90 /** |
|
91 * CSIPExSIPEngine |
|
92 * Class for implementing the SIP Engine for the SIP |
|
93 * Example Application. The Engine provides API functions |
|
94 * for other parts of the Application, and maintains an |
|
95 * internal state machine to handle the SIP session. |
|
96 */ |
|
97 class CSIPExSIPEngine: public CBase, |
|
98 MSIPObserver, |
|
99 MSIPConnectionObserver, |
|
100 MSIPProfileRegistryObserver |
|
101 { |
|
102 |
|
103 public: // Constructors and destructor |
|
104 |
|
105 /** |
|
106 * NewL |
|
107 * Create new instance of SIP Engine. |
|
108 * @param aAppUid Application uid. |
|
109 * @param aObserver Pointer to the Engine Observer. |
|
110 * @return Pointer to new SIP Engine instance. |
|
111 */ |
|
112 IMPORT_C static CSIPExSIPEngine* NewL( TUid aAppUid, |
|
113 MSIPExSIPEngineObserver* aObserver ); |
|
114 |
|
115 /** |
|
116 * Destructor. |
|
117 */ |
|
118 virtual ~CSIPExSIPEngine(); |
|
119 |
|
120 private: |
|
121 |
|
122 /** |
|
123 * C++ default constructor. |
|
124 */ |
|
125 CSIPExSIPEngine(); |
|
126 |
|
127 /** |
|
128 * 2nd phase construction. |
|
129 * @param aAppUid Application uid. |
|
130 * @param aObserver Pointer to the Engine Observer. |
|
131 */ |
|
132 void ConstructL( TUid aAppUid, |
|
133 MSIPExSIPEngineObserver* aObserver ); |
|
134 |
|
135 public: // New functions - services provided by the SIP Engine |
|
136 |
|
137 /** |
|
138 * EnableProfileL |
|
139 * Enable the default profile. |
|
140 * Callback is notified when operation is complete. |
|
141 * Leaves if default SIP profile is not found or profile type is not expected. |
|
142 * Returns true if profile was registered immediately after enabling. |
|
143 */ |
|
144 IMPORT_C TBool EnableProfileL(); |
|
145 |
|
146 /** |
|
147 * DisableProfile |
|
148 * Disable the current profile. |
|
149 * Callback is notified when operation is complete. |
|
150 */ |
|
151 IMPORT_C void DisableProfileL(); |
|
152 |
|
153 |
|
154 /** |
|
155 * SendInvite |
|
156 * Create and send an INVITE to the recipient |
|
157 * identified by the parameter. |
|
158 * @param aSipUri Address of the recipient. |
|
159 */ |
|
160 IMPORT_C void SendInviteL( const TDesC8& aSipUri ); |
|
161 |
|
162 |
|
163 /** |
|
164 * CancelInvite |
|
165 * CANCEL a previously sent INVITE. If a final |
|
166 * response for the INVITE has been sent, the |
|
167 * CANCEL request fails. |
|
168 */ |
|
169 IMPORT_C void CancelInviteL(); |
|
170 |
|
171 |
|
172 /** |
|
173 * AcceptInvite |
|
174 * Send a 200 (OK) response to an INVITE sent |
|
175 * by a remote party. |
|
176 * @param aIPAddr local ip-address. |
|
177 */ |
|
178 IMPORT_C void AcceptInviteL(const TInetAddr& aIPAddr ); |
|
179 |
|
180 |
|
181 /** |
|
182 * DeclineInvite |
|
183 * Send a 488 (Not Acceptable Here) response to |
|
184 * an INVITE sent by a remote party. |
|
185 */ |
|
186 IMPORT_C void DeclineInviteL(); |
|
187 |
|
188 |
|
189 /** |
|
190 * EndSession |
|
191 * Terminate the SIP session by sending a BYE |
|
192 * request. |
|
193 */ |
|
194 IMPORT_C void EndSessionL(); |
|
195 |
|
196 |
|
197 /** |
|
198 * CreateIML |
|
199 * Create an instant message and send it to the |
|
200 * remote party using the MESSAGE method. |
|
201 * @param aMessage The message to be sent. |
|
202 * @param aSipUri Address of the recipient. |
|
203 */ |
|
204 IMPORT_C void CreateIML( const TDesC8& aMessage, |
|
205 const TDesC8& aSipUri ); |
|
206 |
|
207 |
|
208 public: // State machine & internal functionality |
|
209 |
|
210 /** |
|
211 * IMReceivedL |
|
212 * An instant message has been received from the |
|
213 * network. Inform the observer. |
|
214 * @param aTransaction Contains message elements. |
|
215 * Ownership is transferred. |
|
216 */ |
|
217 void IMReceivedL( CSIPServerTransaction* aTransaction ); |
|
218 |
|
219 |
|
220 /** |
|
221 * IMReceived |
|
222 * A non-leaving version of the IMReceivedL, the |
|
223 * possible errors are trapped. |
|
224 * @param aTransaction Contains message elements. |
|
225 * Ownership is transferred. |
|
226 */ |
|
227 void IMReceived( CSIPServerTransaction* aTransaction ); |
|
228 |
|
229 |
|
230 /** |
|
231 * SetCurrentState |
|
232 * Sets the active state of the state machine. |
|
233 * @param aState The current state. |
|
234 */ |
|
235 void SetCurrentState( CSIPExSIPStateBase* aState ); |
|
236 |
|
237 |
|
238 /** |
|
239 * Connection |
|
240 * Sets the active connection. |
|
241 */ |
|
242 CSIPConnection& ConnectionL(); |
|
243 |
|
244 /** |
|
245 * Profile |
|
246 * Returns the enabled profile. |
|
247 */ |
|
248 CSIPProfile& Profile(); |
|
249 |
|
250 |
|
251 /** |
|
252 * SetServerTx |
|
253 * Sets the current Server Transaction. |
|
254 * The ownership is transferred to the Engine. |
|
255 * @param aTx The transaction. |
|
256 */ |
|
257 void SetServerTx( CSIPServerTransaction* aTx ); |
|
258 |
|
259 /** |
|
260 * ServerTx |
|
261 * Gets the current Server Transaction. |
|
262 */ |
|
263 CSIPServerTransaction& ServerTx(); |
|
264 |
|
265 |
|
266 /** |
|
267 * SetClientTx |
|
268 * Sets the current Client Transaction. |
|
269 * The ownership is transferred to the Engine. |
|
270 * @param aTx The transaction. |
|
271 */ |
|
272 void SetClientTx( CSIPClientTransaction* aTx ); |
|
273 |
|
274 /** |
|
275 * ClearClientTx |
|
276 * Deletes the current Client Transaction. |
|
277 */ |
|
278 void ClearClientTx(); |
|
279 |
|
280 /** |
|
281 * ClientTx |
|
282 * Gets the current Client Transaction. |
|
283 */ |
|
284 CSIPClientTransaction& ClientTx(); |
|
285 |
|
286 |
|
287 /** |
|
288 * SetDialogAssoc |
|
289 * Sets the current Invite Dialog Association. |
|
290 * @param aAssoc The Dialog Assoc. |
|
291 */ |
|
292 void SetDialogAssoc( CSIPInviteDialogAssoc& aAssoc ); |
|
293 |
|
294 |
|
295 /** |
|
296 * DialogAssoc |
|
297 * Returns the current Invite Dialog Association. |
|
298 */ |
|
299 CSIPInviteDialogAssoc& DialogAssoc(); |
|
300 |
|
301 |
|
302 public: // Methods from base classes |
|
303 |
|
304 // From MSIPObserver |
|
305 |
|
306 /** |
|
307 * IncomingRequest (from MSIPObserver) |
|
308 * A SIP request has been received from the network. |
|
309 * @param aIapId The IapId from which |
|
310 * the SIP request was received. |
|
311 * @param aTransaction contains local address, |
|
312 * remote address of a sip message, |
|
313 * as well as optional SIP message method, headers and body. |
|
314 * The ownership is transferred. |
|
315 */ |
|
316 |
|
317 void IncomingRequest( TUint32 aIapId, |
|
318 CSIPServerTransaction* aTransaction ); |
|
319 |
|
320 /** |
|
321 * TimedOut (from MSIPObserver) |
|
322 */ |
|
323 |
|
324 void TimedOut( CSIPServerTransaction& aSIPServerTransaction ); |
|
325 |
|
326 |
|
327 // From MSIPConnectionObserver |
|
328 |
|
329 /** |
|
330 * IncomingRequest (from MSIPConnectionObserver) |
|
331 * A SIP request outside a dialog has been received from the network. |
|
332 * |
|
333 * @param aTransaction SIP server transaction. The ownership is |
|
334 * transferred. |
|
335 */ |
|
336 void IncomingRequest( CSIPServerTransaction* aTransaction ); |
|
337 |
|
338 /** |
|
339 * IncomingRequest (from MSIPConnectionObserver) |
|
340 * A SIP request within a dialog has been received from the network. |
|
341 * The client must resolve the actual dialog association to which |
|
342 * this request belongs. |
|
343 * |
|
344 * @param aTransaction SIP server transaction. The ownership is |
|
345 * transferred. |
|
346 * @param aDialog the dialog that this transaction belongs to. |
|
347 */ |
|
348 void IncomingRequest( CSIPServerTransaction* aTransaction, |
|
349 CSIPDialog& aDialog ); |
|
350 |
|
351 /** |
|
352 * IncomingResponse (from MSIPConnectionObserver) |
|
353 */ |
|
354 void IncomingResponse( CSIPClientTransaction& aTransaction ); |
|
355 |
|
356 /** |
|
357 * IncomingResponse (from MSIPConnectionObserver) |
|
358 * A SIP response that is within a dialog association or creates |
|
359 * a dialog association. |
|
360 * |
|
361 * @param aTransaction contains response elements. |
|
362 * @param aDialogAssoc a dialog association. |
|
363 */ |
|
364 void IncomingResponse( CSIPClientTransaction& aTransaction, |
|
365 CSIPDialogAssocBase& aDialogAssoc ); |
|
366 |
|
367 /** |
|
368 * IncomingResponse (from MSIPConnectionObserver) |
|
369 */ |
|
370 void IncomingResponse( CSIPClientTransaction& aTransaction, |
|
371 CSIPInviteDialogAssoc* aDialogAssoc ); |
|
372 |
|
373 |
|
374 /** |
|
375 * IncomingResponse (from MSIPConnectionObserver) |
|
376 */ |
|
377 void IncomingResponse( CSIPClientTransaction& aTransaction, |
|
378 CSIPRegistrationBinding& aRegistration ); |
|
379 |
|
380 |
|
381 /** |
|
382 * An asynchronous error has occurred in the stack related to the |
|
383 * request indicated by the given transaction. |
|
384 * |
|
385 * @param aError system wide or sip error code |
|
386 * @param aTransaction failed transaction. |
|
387 * @param aSIPConnection a SIP connection |
|
388 */ |
|
389 void ErrorOccured( TInt aError, |
|
390 CSIPTransactionBase& aTransaction ); |
|
391 |
|
392 /** |
|
393 * An asynchronous error has occurred in the stack related |
|
394 * to the request indicated by the given transaction. |
|
395 * |
|
396 * @param aError system wide or sip error code |
|
397 * @param aTransaction the failed transaction. |
|
398 * @param aRegistration the failed registration. |
|
399 */ |
|
400 void ErrorOccured( TInt aError, |
|
401 CSIPClientTransaction& aTransaction, |
|
402 CSIPRegistrationBinding& aRegistration ); |
|
403 |
|
404 /** |
|
405 * An asynchronous error has occured related to a request within |
|
406 * an existing dialog. |
|
407 * |
|
408 * @param aError system wide or sip error code |
|
409 * @param aTransaction the failed transaction. |
|
410 * @param aDialogAssoc the failed dialog associoation. |
|
411 */ |
|
412 void ErrorOccured( TInt aError, |
|
413 CSIPTransactionBase& aTransaction, |
|
414 CSIPDialogAssocBase& aDialogAssoc ); |
|
415 |
|
416 /** |
|
417 * An asynchronous error has occured related to a refresh |
|
418 * |
|
419 * @param aError system wide or sip error code |
|
420 * @param aSIPRefresh original refresh object. |
|
421 */ |
|
422 void ErrorOccured( TInt aError, CSIPRefresh& aSIPRefresh ); |
|
423 |
|
424 /** |
|
425 * An asynchronous error has occured related to a periodical refresh |
|
426 * that relates to a registration. |
|
427 * |
|
428 * @param aError system wide or sip error code; |
|
429 * KErrCouldNotConnect if the refresh has failed |
|
430 * due to the suspended connection. |
|
431 * @param aRegistration associated registration. |
|
432 */ |
|
433 void ErrorOccured( TInt aError, |
|
434 CSIPRegistrationBinding& aRegistration ); |
|
435 |
|
436 /** |
|
437 * An asynchronous error has occured related to a periodical refresh |
|
438 * that belongs to SIP dialog association. |
|
439 * |
|
440 * @param aError system wide or sip error code; |
|
441 * KErrCouldNotConnect if the refresh has failed |
|
442 * due to the suspended connection. |
|
443 * @param aDialogAssoc SIP dialog association. |
|
444 */ |
|
445 void ErrorOccured( TInt aError, |
|
446 CSIPDialogAssocBase& aDialogAssoc ); |
|
447 |
|
448 /** |
|
449 * SIP stack has completed UAC core INVITE transaction 64*T1 seconds |
|
450 * after the reception of the first 2xx response. No more 2xx responses |
|
451 * can be received to the issued single INVITE. |
|
452 * |
|
453 * If the INVITE transaction does not create a dialog, or the INVITE |
|
454 * transaction encounters an error, this event will not be sent. |
|
455 * |
|
456 * @param aTransaction a complete UAC core INVITE transaction |
|
457 */ |
|
458 void InviteCompleted( CSIPClientTransaction& aTransaction ); |
|
459 |
|
460 /** |
|
461 * Invite was canceled with the CANCEL |
|
462 * @param aTransaction a canceled INVITE UAS transaction |
|
463 */ |
|
464 void InviteCanceled( CSIPServerTransaction& aTransaction ); |
|
465 |
|
466 /** |
|
467 * Connection state has changed. |
|
468 * If connection state has changed to EInactive or EUnavailable, |
|
469 * SIP stack has removed all stand-alone SIP refreshes, registrations |
|
470 * and dialog associations that client requested to refresh. Client may |
|
471 * re-issue refresh requests (stand-alone, registration or dialog |
|
472 * association related) when connection becomes EActive again. |
|
473 * SIP stack also terminates all pending sip client transactions and no |
|
474 * errors are reported back to the client about the terminated |
|
475 * transactions nor about removed refreshes in order to avoid event |
|
476 * flood. |
|
477 * |
|
478 * @param aState indicates the current connection state |
|
479 */ |
|
480 void ConnectionStateChanged( CSIPConnection::TState aState ); |
|
481 |
|
482 |
|
483 // From MSIPProfileRegistryObserver |
|
484 |
|
485 |
|
486 /** |
|
487 * An event related to SIP Profile has accorred |
|
488 * @param aProfileId a profile Id |
|
489 * @param aEvent an occurred event |
|
490 **/ |
|
491 void ProfileRegistryEventOccurred( TUint32 aProfileId, TEvent aEvent ); |
|
492 |
|
493 /** |
|
494 * An asynchronous error has occurred related to SIP profile |
|
495 * Event is send to those observers, who have the |
|
496 * corresponding profile instantiated. |
|
497 * @param aProfileId the id of failed profile |
|
498 * @param aError an occurred error |
|
499 */ |
|
500 void ProfileRegistryErrorOccurred( TUint32 aProfileId, TInt aError ); |
|
501 |
|
502 |
|
503 |
|
504 public: // Methods internal to the Engine |
|
505 |
|
506 /** |
|
507 * CreateToHeaderLC |
|
508 * Return a To header object based on URI. |
|
509 * @param aSipUri The URI address as a string. |
|
510 * @return Pointer to CSIPToHeader instance. |
|
511 * Ownership is transferred. |
|
512 */ |
|
513 CSIPToHeader* CreateToHeaderLC( const TDesC8& aSipUri ); |
|
514 |
|
515 /** |
|
516 * CreateReqElementsLC |
|
517 * Return a RequestElements object based on URI. |
|
518 * @param aSipUri The URI address as a string. |
|
519 * @return Pointer to CSIPRequestElements instance. |
|
520 */ |
|
521 CSIPRequestElements* CreateReqElementsLC( const TDesC8& aSipUri ); |
|
522 |
|
523 /** |
|
524 * CreateMessageElementsLC |
|
525 * Instantiate a Message Elements object. |
|
526 * @return Pointer to CSIPMessageElements instance. |
|
527 * Ownership is transferred. |
|
528 */ |
|
529 CSIPMessageElements* CreateMessageElementsLC(); |
|
530 |
|
531 /** |
|
532 * ConvertToUri8LC |
|
533 * Convert textual representation of uri to CUri8 |
|
534 * @return Pointer to CUri8 instance. |
|
535 * Ownership is transferred. |
|
536 */ |
|
537 CUri8* ConvertToUri8LC( const TDesC8& aSipUri ); |
|
538 |
|
539 /** |
|
540 * SdpDocumentLC |
|
541 * Instantiate a SDP Document object. |
|
542 * @return Pointer to CSdpDocument instance. |
|
543 * Ownership is transferred. |
|
544 */ |
|
545 CSdpDocument* SdpDocumentLC(); |
|
546 |
|
547 /** |
|
548 * SdpBodyL |
|
549 * Return SDP message body in textual form. |
|
550 * @return Pointer to SDP Document as HBufC8. |
|
551 * Ownership is transferred. |
|
552 */ |
|
553 HBufC8* SdpBodyL( CSdpDocument* aDocument ); |
|
554 |
|
555 |
|
556 /** |
|
557 * Get SDP codec string pool. Open string pool if not opened. |
|
558 * |
|
559 * @return String pool. |
|
560 */ |
|
561 RStringPool StringPoolL(); |
|
562 |
|
563 |
|
564 /** |
|
565 * IPAddressFromResponseElementsL |
|
566 * Get IP Address from the Response Elements |
|
567 * received from peer. |
|
568 * @param aRespElem The Response Elements. |
|
569 */ |
|
570 const TInetAddr IPAddressFromResponseElementsL( |
|
571 const CSIPResponseElements& aRespElem ); |
|
572 |
|
573 |
|
574 /** |
|
575 * Observer |
|
576 * Return a pointer to the Engine Observer class. |
|
577 */ |
|
578 MSIPExSIPEngineObserver* Observer(); |
|
579 |
|
580 private: |
|
581 |
|
582 /** |
|
583 * SessionId |
|
584 * Return the Session ID |
|
585 */ |
|
586 TInt64 SessionId(); |
|
587 |
|
588 void MediaFieldsL( CSdpDocument* aDocument ); |
|
589 |
|
590 /** |
|
591 * CurrentConnection returns currently used connection. |
|
592 * Can be used also for checking if connection exists. |
|
593 * Returns either iConnection, iNotOwnedConnection or NULL |
|
594 */ |
|
595 CSIPConnection* CurrentConnection(); |
|
596 |
|
597 /** |
|
598 * Handle SIP profile registration event |
|
599 * @param aSIPProfileId id of registered profile |
|
600 */ |
|
601 void HandleProfileRegistered( TUint32 aSIPProfileId ); |
|
602 |
|
603 /** |
|
604 * Handle SIP profile deregistration event |
|
605 * @param aSIPProfileId id of deregistered profile |
|
606 */ |
|
607 void HandleProfileDeregistered( TUint32 aSIPProfileId ); |
|
608 |
|
609 /** |
|
610 * Handle SIP profile destruction event. |
|
611 * Event is send to those observers, who have the |
|
612 * corresponding profile instantiated. |
|
613 * @param aSIPProfileId id of profile which was destroyed |
|
614 */ |
|
615 void HandleProfileDestroyed( TUint32 aSIPProfileId ); |
|
616 |
|
617 |
|
618 |
|
619 private: // Data |
|
620 |
|
621 TInt64 iSessionId; |
|
622 TInetAddr iLocalAddr; |
|
623 MSIPExSIPEngineObserver* iObserver; |
|
624 |
|
625 CSIP* iSIP; |
|
626 CSIPProfile* iProfile; |
|
627 CSIPProfileRegistry* iProfileRegistry; |
|
628 CSIPConnection* iConnection; |
|
629 CSIPInviteDialogAssoc* iDialogAssoc; |
|
630 |
|
631 CSIPConnection::TState iConnState; |
|
632 |
|
633 CSIPExSIPStateBase* iCurrentState; |
|
634 CSIPClientTransaction* iClientTx; |
|
635 CSIPServerTransaction* iServerTx; |
|
636 |
|
637 // States of the machine |
|
638 CSIPExSIPIdleState* iIdle; |
|
639 CSIPExSIPClientEstablishingState* iClientEstablishing; |
|
640 CSIPExSIPClientOfferingState* iClientOffering; |
|
641 CSIPExSIPServerOfferingState* iServerOffering; |
|
642 CSIPExSIPServerEstablishingState* iServerEstablishing; |
|
643 CSIPExSIPEstablishedState* iEstablished; |
|
644 CSIPExSIPTerminatingState* iTerminating; |
|
645 |
|
646 }; |
|
647 |
|
648 #endif // _SIPEXSIPENGINE_H_ |