|
1 /* |
|
2 * Copyright (c) 2006-2009 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: SIMPLE engine core. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef CSimpleSIPConnection_H |
|
22 #define CSimpleSIPConnection_H |
|
23 |
|
24 |
|
25 // INCLUDES |
|
26 #include <e32base.h> |
|
27 #include <sip.h> |
|
28 #include <sipobserver.h> |
|
29 #include "simplecommon.h" |
|
30 #include "simplesipconncallback.h" |
|
31 #include "simplecommon.h" |
|
32 #include "simplerefreshtimer.h" |
|
33 #include "simplerequest.h" |
|
34 #include "simplesettings.h" |
|
35 |
|
36 // FORWARD DECLARATIONS |
|
37 class CSimpleSipProfileObserver; |
|
38 class CSIPClientTransaction; |
|
39 class CSimpleRefreshTimer; |
|
40 class CSIPMessageElements; |
|
41 class CSIPSubscribeDialogAssoc; |
|
42 class CSimpleSipConnectionObserver; |
|
43 |
|
44 // CLASS DECLARATION |
|
45 |
|
46 |
|
47 |
|
48 /** |
|
49 * CSimpleSipConnection |
|
50 * |
|
51 * @lib simplesiputils |
|
52 * @since S60 v3.2 |
|
53 */ |
|
54 |
|
55 class CSimpleSipConnection : public CBase, |
|
56 public MSIPObserver, |
|
57 public MSimpleSipConnCallback |
|
58 { |
|
59 |
|
60 public: |
|
61 |
|
62 /** |
|
63 * Subscription types |
|
64 */ |
|
65 enum TSimpleSubsType |
|
66 { |
|
67 ESubsRegular, |
|
68 ESubsWinfo, |
|
69 ESubsList |
|
70 }; |
|
71 |
|
72 /** |
|
73 * Two-phased constructor. |
|
74 */ |
|
75 IMPORT_C static CSimpleSipConnection* NewL(); |
|
76 |
|
77 /** |
|
78 * Destructor. |
|
79 */ |
|
80 IMPORT_C virtual ~CSimpleSipConnection(); |
|
81 |
|
82 /** |
|
83 * Dispatch a client request |
|
84 * |
|
85 * @since S60 v3.2 |
|
86 * @param aReq client request |
|
87 */ |
|
88 IMPORT_C void DispatchReqL( MSimpleEngineRequest& aReq ); |
|
89 |
|
90 /** |
|
91 * SIP Status accessor |
|
92 * |
|
93 * @since S60 v3.2 |
|
94 * @param aOpId operation id |
|
95 * @param aRetryAfter SIP header value, OUTPUT |
|
96 * @return SIP status, 0 if not found |
|
97 */ |
|
98 IMPORT_C TUint SIPStatus( TInt aOpId, TInt& aRetryAfter ); |
|
99 |
|
100 /** |
|
101 * SIP connection state accessor |
|
102 * |
|
103 * @since S60 v3.2 |
|
104 * @return SIP state |
|
105 */ |
|
106 IMPORT_C TSimpleSipState SIPState(); |
|
107 |
|
108 /** |
|
109 * current SIP Identity accessor |
|
110 * @return SIP identity |
|
111 */ |
|
112 IMPORT_C TPtrC8 CurrentSIPIdentityL(); |
|
113 |
|
114 /** |
|
115 * SIP Subscription-state accessor |
|
116 * @param aReq corresponding engine's request |
|
117 * @return subscription-state. |
|
118 */ |
|
119 IMPORT_C MSimpleEngineRequest::TSimpleSipSubscriptionState SipSubscriptionState( |
|
120 MSimpleEngineRequest& aReq ); |
|
121 |
|
122 /** |
|
123 * Set service id |
|
124 * @param aServiceId new service id |
|
125 */ |
|
126 IMPORT_C void SetServiceId( TInt32 aServiceId ); |
|
127 |
|
128 /** |
|
129 * Search the corresponding client request |
|
130 * |
|
131 * @since S60 v3.2 |
|
132 * @param aTrans SIP transaction |
|
133 * @return request or NULL if request not found |
|
134 */ |
|
135 CSimpleRequest* GetRequest( CSIPClientTransaction& aTrans ); |
|
136 |
|
137 /** |
|
138 * Search the corresponding client request |
|
139 * |
|
140 * @since S60 v3.2 |
|
141 * @param aDialog SIP dialog |
|
142 * @return initial SUBSCRIBE request or NULL if request not found |
|
143 */ |
|
144 CSimpleRequest* GetdDialogRequest( const CSIPDialog& aDialog ); |
|
145 |
|
146 /** |
|
147 * Handles publish response. |
|
148 * This reads SIP-ETAG and resets refresh timer. |
|
149 * |
|
150 * @since S60 v3.2 |
|
151 * @param aMesElems SIP message elements |
|
152 * @param aReq corresponding engine's request |
|
153 */ |
|
154 void HandlePublishRespL( |
|
155 const CSIPMessageElements& aMesElems, |
|
156 CSimpleRequest* aReq ); |
|
157 |
|
158 /** |
|
159 * Time to refresh a request |
|
160 * |
|
161 * @since S60 v3.2 |
|
162 * @param aReq request |
|
163 */ |
|
164 void StartToRefreshL( CSimpleRequest& aReq ); |
|
165 |
|
166 /** |
|
167 * Time to check expiration |
|
168 * |
|
169 * @since S60 v3.2 |
|
170 * @param aReq request |
|
171 */ |
|
172 void StartToCheckExpiryL( CSimpleRequest& aReq ); |
|
173 |
|
174 /** |
|
175 * Handles server request in a dialog |
|
176 * This resets refresh timer when needed. |
|
177 * |
|
178 * @since S60 v3.2 |
|
179 * @param aMesElems SIP message elements |
|
180 * @param aReq corresponding engine's request |
|
181 * @param aMethod SIP method |
|
182 */ |
|
183 void HandleDialogRequestL( |
|
184 const CSIPMessageElements& aMesElems, |
|
185 CSimpleRequest& aReq, |
|
186 const TDesC8& aMethod ); |
|
187 |
|
188 /** |
|
189 * Retry publication, with a body when pending data exists. |
|
190 * |
|
191 * @since S60 v3.2 |
|
192 * @param aReq request |
|
193 * @return error code |
|
194 */ |
|
195 TInt DoSendPendingPublish( CSimpleRequest& aReq ); |
|
196 |
|
197 // from base class MSIPObserver |
|
198 |
|
199 /** |
|
200 * From MSIPObserver. |
|
201 * A SIP request has been received from the network. |
|
202 * This function is called when the SIP request was received using such |
|
203 * an IAP, for which the application has not created a CSIPConnection |
|
204 * object. |
|
205 * |
|
206 * @since S60 v3.2 |
|
207 * @pre aTransaction != 0 |
|
208 * @param aIapId The IapId from which the SIP request was received. |
|
209 * @param aTransaction contains local address, remote address of a SIP |
|
210 * message, as well as optional SIP message method, headers and |
|
211 * body. The ownership is transferred. |
|
212 */ |
|
213 void IncomingRequest( TUint32 aIapId, |
|
214 CSIPServerTransaction* aTransaction ); |
|
215 |
|
216 /** |
|
217 * From MSIPObserver. |
|
218 * The received SIP request time-outed and it is invalid i.e. cannot be used |
|
219 * anymore. |
|
220 * This will be called if the user fails to create a SIP connection and |
|
221 * does not send an appropriate SIP response. |
|
222 * |
|
223 * @since S60 v3.2 |
|
224 * @param aTransaction The time-outed transaction. |
|
225 */ |
|
226 void TimedOut( CSIPServerTransaction& aTransaction ); |
|
227 |
|
228 // from base class MSimpleSipConnCallback |
|
229 |
|
230 /** |
|
231 * From MSimpleSipConnCallback. |
|
232 * Connection state is changed |
|
233 * |
|
234 * @since S60 v3.2 |
|
235 * @param aState new SIP state |
|
236 */ |
|
237 void ConnectionStateChange( |
|
238 TSimpleSipState aState, TInt aSipError ); |
|
239 |
|
240 /** |
|
241 * Handle received message |
|
242 * |
|
243 * @since S60 v5.0 |
|
244 * @param aFrom message received from |
|
245 * @param aContent message content |
|
246 * @return error code |
|
247 */ |
|
248 TInt HandleReceivedMessage( const TDesC8& aFrom, |
|
249 const TDesC8& aContent ); |
|
250 |
|
251 /** |
|
252 * Connection method has changed (Roaming). |
|
253 * |
|
254 * @since S60 3.2.3 |
|
255 */ |
|
256 void ConnectionChanged(); |
|
257 |
|
258 protected: |
|
259 |
|
260 /** |
|
261 * C++ default constructor. |
|
262 */ |
|
263 CSimpleSipConnection(); |
|
264 |
|
265 private: |
|
266 |
|
267 void ConstructL(); |
|
268 |
|
269 /** |
|
270 * Search the corresponding client request |
|
271 * |
|
272 * @since S60 v3.2 |
|
273 * @param aTrans SIP transaction |
|
274 * @return request or NULL if request not found |
|
275 */ |
|
276 CSimpleRequest* GetCliRequest( MSimpleEngineRequest& aRequest ); |
|
277 |
|
278 /** |
|
279 * Read static settings and register SIP profile. |
|
280 * If already registered then uses the current registeration. |
|
281 * |
|
282 * @since S60 v3.2 |
|
283 * @param aReq request |
|
284 * @leave KErrNotFound if SIP profile is not found |
|
285 */ |
|
286 void RegisterL( MSimpleEngineRequest& aReg ); |
|
287 |
|
288 /** |
|
289 * Start to listen to status events |
|
290 * |
|
291 * @since S60 v3.2 |
|
292 * @param aReq request |
|
293 */ |
|
294 void ListenStatusL( MSimpleEngineRequest& aReq ); |
|
295 |
|
296 /** |
|
297 * Start publish transaction |
|
298 * |
|
299 * @since S60 v3.2 |
|
300 * @param aReq request |
|
301 */ |
|
302 void StartPublishL( MSimpleEngineRequest& aReq ); |
|
303 |
|
304 /** |
|
305 * Request instant message receiving |
|
306 * |
|
307 * @since S60 v5.0 |
|
308 * @param aReq request |
|
309 */ |
|
310 void RequestInstantMessageReceivingL( MSimpleEngineRequest& aReq ); |
|
311 |
|
312 /** |
|
313 * Send instant message |
|
314 * |
|
315 * @since S60 v5.0 |
|
316 * @param aReq request |
|
317 */ |
|
318 void SendInstantMessageL( MSimpleEngineRequest& aReq ); |
|
319 |
|
320 /** |
|
321 * Update publish |
|
322 * |
|
323 * @since S60 v3.2 |
|
324 * @param aReq request |
|
325 */ |
|
326 void ModifyPublishL( MSimpleEngineRequest& aReq ); |
|
327 |
|
328 /** |
|
329 * Stop publish |
|
330 * |
|
331 * @since S60 v3.2 |
|
332 * @param aReq request |
|
333 */ |
|
334 void StopPublishL( MSimpleEngineRequest& aReq ); |
|
335 |
|
336 /** |
|
337 * Start subscription |
|
338 * if aReq expiry time is 0 then it means fetch presence once |
|
339 * |
|
340 * @since S60 v3.2 |
|
341 * @param aReq request |
|
342 */ |
|
343 void SubscribeL( MSimpleEngineRequest& aReq ); |
|
344 |
|
345 /** |
|
346 * Start list subscription |
|
347 * if aReq expiry time is 0 then it means fetch presence once |
|
348 * |
|
349 * @since S60 v3.2 |
|
350 * @param aReq request |
|
351 */ |
|
352 void SubscribeListL( MSimpleEngineRequest& aReq ); |
|
353 |
|
354 /** |
|
355 * Start WINFO subscription |
|
356 * |
|
357 * @since S60 v3.2 |
|
358 * @param aReq request |
|
359 */ |
|
360 void SubscribeWinfoL( MSimpleEngineRequest& aReq ); |
|
361 |
|
362 /** |
|
363 * Stop subscription |
|
364 * |
|
365 * @since S60 v3.2 |
|
366 * @param aReq request |
|
367 */ |
|
368 void StopSubscribeL( MSimpleEngineRequest& aReq ); |
|
369 |
|
370 /** |
|
371 * Delete all pending client requests |
|
372 * |
|
373 * @since S60 v3.2 |
|
374 */ |
|
375 void DeleteRequests(); |
|
376 |
|
377 /** |
|
378 * Delete all pending specified type of requests. |
|
379 * |
|
380 * @since S60 5.0 |
|
381 * @param aRequestType request type |
|
382 */ |
|
383 void DeleteRequests( CSimpleRequest::TSimpleSipReqType aRequestType ); |
|
384 |
|
385 /** |
|
386 * Destroy the request |
|
387 * |
|
388 * @since S60 v3.2 |
|
389 * @param aReq request |
|
390 */ |
|
391 void DeleteRequest( MSimpleEngineRequest& aReq ); |
|
392 |
|
393 /** |
|
394 * Destroy the request with a delay |
|
395 * |
|
396 * @since S60 v3.2 |
|
397 * @param aReq request |
|
398 */ |
|
399 void DeleteRequestStart( MSimpleEngineRequest& aReq ); |
|
400 |
|
401 /** |
|
402 * Complete all pending register client requests |
|
403 * |
|
404 * @since S60 v3.2 |
|
405 * @param aStatus status |
|
406 */ |
|
407 void CompleteRegisterRequests( TInt aStatus ); |
|
408 |
|
409 /** |
|
410 * Complete all open regular client requests |
|
411 * |
|
412 * @since S60 v3.2 |
|
413 * @param aStatus status |
|
414 */ |
|
415 void CompleteRegularRequests( TInt aStatus ); |
|
416 |
|
417 /** |
|
418 * Complete status event request |
|
419 * |
|
420 * @since S60 v3.2 |
|
421 */ |
|
422 void CompleteStatusRequest(); |
|
423 |
|
424 /** |
|
425 * Fill the headers and content for SIP PUBLISH request |
|
426 * and send the SIP request, |
|
427 * |
|
428 * @since S60 v3.2 |
|
429 * @param aRemoteURI remote request-URI |
|
430 * @param aExpiry expires time |
|
431 * @param aContent payload data |
|
432 * @param aSipIfMatch sip-if-match/ETag SIP header value |
|
433 * @return SIP transaction |
|
434 */ |
|
435 CSIPClientTransaction* DoPublishL( |
|
436 const TDesC8& aRemoteURI, TInt aExpiry, |
|
437 const TDesC8& aContent, const TDesC8& aSipIfMatch, |
|
438 const TDesC8& aContentType ); |
|
439 |
|
440 /** |
|
441 * Send SIP SUBSCRIBE request |
|
442 * |
|
443 * @since S60 v3.2 |
|
444 * @param aRemoteURI remote request-URI |
|
445 * @param aExpiry expires time |
|
446 * @param aContent payload data |
|
447 * @param aSubsDialog subscription dialog, OUT |
|
448 * @param aRefesh ETrue if subscription is refreshed automatically |
|
449 * @param aType subscription use case |
|
450 * @param aAnonymous ETrue if anonymous subscription is wanted |
|
451 * (should be EFalse always when aType is WINFO subscription) |
|
452 * @return SIP transaction |
|
453 */ |
|
454 CSIPClientTransaction* DoSubscribeL( |
|
455 const TDesC8& aRemoteURI, |
|
456 TInt aExpiry, |
|
457 const TDesC8& aContent, |
|
458 CSIPSubscribeDialogAssoc*& aSubsDialog, |
|
459 TBool aRefresh, |
|
460 TSimpleSubsType aType, |
|
461 TBool aAnonymous ); |
|
462 |
|
463 /** |
|
464 * Read static settings and register default SIP profile. |
|
465 * If already registered then uses the current registeration. |
|
466 * |
|
467 * @since S60 v3.2 |
|
468 * @param aReq request |
|
469 * @leave KErrNotFound if SIP profile is not found |
|
470 */ |
|
471 void RegisterDefaultL( MSimpleEngineRequest& aReg ); |
|
472 |
|
473 /** |
|
474 * Read static settings and register a specified SIP profile. |
|
475 * If already registered then uses the current registeration. |
|
476 * |
|
477 * @since S60 v3.2 |
|
478 * @param aReq request |
|
479 * @leave KErrNotFound if SIP profile is not found |
|
480 */ |
|
481 void RegisterAnyL( MSimpleEngineRequest& aReg ); |
|
482 |
|
483 /** |
|
484 * Set SIP state |
|
485 * |
|
486 * @since S60 v3.2 |
|
487 * @param aState SIP state |
|
488 */ |
|
489 void SetSipState( TSimpleSipState aState ); |
|
490 |
|
491 /** |
|
492 * Converts ascii reason string into enum and stores into aR entity |
|
493 * |
|
494 * @since S60 v3.2 |
|
495 * @param aReason reason text |
|
496 * @param aR request entity |
|
497 */ |
|
498 void DoSetResponseReason( |
|
499 const TDesC8& aReason, CSimpleRequest& aR ); |
|
500 |
|
501 /** |
|
502 * Converts ascii reason string into enum and stores into aR entity |
|
503 * |
|
504 * @since S60 v3.2 |
|
505 * @param aReason reason |
|
506 * @param aR client request entity |
|
507 */ |
|
508 void DoSetResponseReason2( |
|
509 TInt aReason, MSimpleEngineRequest& aR ); |
|
510 |
|
511 /** |
|
512 * Is the reson code permanent reason |
|
513 * |
|
514 * @since S60 v3.2 |
|
515 * @param aReason error code |
|
516 * @return TRUE if permanent resason and should not be retried. |
|
517 */ |
|
518 TBool IsPermanentReason( TInt aReason ); |
|
519 |
|
520 /** |
|
521 * Increase iCurrentNbrSubs |
|
522 * |
|
523 * @since S60 v3.2 |
|
524 */ |
|
525 void IncreaseNbrSubs(); |
|
526 |
|
527 /** |
|
528 * Decrease iCurrentNbrSubs |
|
529 * |
|
530 * @since S60 v3.2 |
|
531 */ |
|
532 void DecreaseNbrSubs(); |
|
533 |
|
534 /** |
|
535 * Refresh or retry to publish |
|
536 * |
|
537 * @since S60 v3.2 |
|
538 * @param aReq request |
|
539 */ |
|
540 void DoRefreshPublishL( CSimpleRequest& aReq ); |
|
541 |
|
542 /** |
|
543 * Retry to subscribe |
|
544 * |
|
545 * @since S60 v3.2 |
|
546 * @param aReq request |
|
547 */ |
|
548 void DoRefreshSubscribe( CSimpleRequest& aReq ); |
|
549 |
|
550 /** |
|
551 * Create a dialog |
|
552 * |
|
553 * @since S60 v3.2 |
|
554 * @param aReq request |
|
555 */ |
|
556 void DoCreateDialogL( CSimpleRequest& aReq ); |
|
557 |
|
558 /** |
|
559 * Handle pending operations after network resume |
|
560 * |
|
561 * @since S60 v3.2 |
|
562 */ |
|
563 void HandlePendings( ); |
|
564 |
|
565 /** |
|
566 * Update iSipState. |
|
567 * Recognize if both SIP connection and SIP Profile are active. |
|
568 * @param aState SIP state |
|
569 */ |
|
570 void RecognizeSipState( TSimpleSipState aState ); |
|
571 |
|
572 /** |
|
573 * Handle received message |
|
574 * |
|
575 * @since S60 v5.0 |
|
576 * @param aFrom message received from |
|
577 * @param aContent message content |
|
578 * @param aRequest SIMPLE request |
|
579 * @return error code |
|
580 */ |
|
581 void DoHandleReceivedMessageL( const TDesC8& aFrom, |
|
582 const TDesC8& aContent, CSimpleRequest& aRequest ); |
|
583 |
|
584 /** |
|
585 * Stores ETag to vimpstsettingstore |
|
586 * |
|
587 * @since S60 5.0 |
|
588 */ |
|
589 void StoreETagL( HBufC8& aTag ); |
|
590 |
|
591 private: // Data |
|
592 |
|
593 /** |
|
594 * SIP Engine connection |
|
595 * Own |
|
596 */ |
|
597 CSIP* iSip; |
|
598 |
|
599 /** |
|
600 * SIP connection |
|
601 * Own |
|
602 */ |
|
603 CSIPConnection* iSipConnection; |
|
604 |
|
605 /** |
|
606 * SIP connection observer |
|
607 * Own |
|
608 */ |
|
609 CSimpleSipConnectionObserver* iConnectionObserver; |
|
610 |
|
611 /** |
|
612 * Engine SIP state. |
|
613 * Active only if both SIP Connection and SIP Profile are active. |
|
614 */ |
|
615 TSimpleSipState iSipState; |
|
616 |
|
617 /** |
|
618 * SIP profile observer |
|
619 * Own |
|
620 */ |
|
621 CSimpleSipProfileObserver* iProfileObserver; |
|
622 |
|
623 /** |
|
624 * Queue for client requests |
|
625 */ |
|
626 TDblQue<CSimpleRequest> iRequestList; |
|
627 |
|
628 /** |
|
629 * Engine settings |
|
630 */ |
|
631 TSimpleSettings iSettings; |
|
632 |
|
633 /** |
|
634 * File system |
|
635 */ |
|
636 RFs iFs; |
|
637 |
|
638 /** |
|
639 * Current number of subscriptions |
|
640 */ |
|
641 TUint iCurrentNbrSubs; |
|
642 |
|
643 /** |
|
644 * Service id of current service |
|
645 */ |
|
646 TInt32 iServiceId; |
|
647 |
|
648 #ifdef _DEBUG |
|
649 friend class T_CSimpleSipConnection; |
|
650 #endif |
|
651 }; |
|
652 |
|
653 #endif |
|
654 |
|
655 // End of File |