1 /* |
1 /* |
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
34 #include <siprequestelements.h> |
34 #include <siprequestelements.h> |
35 #include <sipclienttransaction.h> |
35 #include <sipclienttransaction.h> |
36 #include <siprefresh.h> |
36 #include <siprefresh.h> |
37 #include <sipmessageelements.h> |
37 #include <sipmessageelements.h> |
38 #include <sipsubscribedialogassoc.h> |
38 #include <sipsubscribedialogassoc.h> |
39 #include <sipregistrationcontext.h> |
|
40 |
39 |
41 // sip codec api |
40 // sip codec api |
42 #include <sipfromheader.h> |
41 #include <sipfromheader.h> |
43 #include <siptoheader.h> |
42 #include <siptoheader.h> |
44 #include <sipexpiresheader.h> |
43 #include <sipexpiresheader.h> |
50 #include <sipextensionheader.h> |
49 #include <sipextensionheader.h> |
51 #include <sipsubscriptionstateheader.h> |
50 #include <sipsubscriptionstateheader.h> |
52 #include <sipsupportedheader.h> |
51 #include <sipsupportedheader.h> |
53 #include <sipacceptheader.h> |
52 #include <sipacceptheader.h> |
54 |
53 |
55 #include <cvimpstsettingsstore.h> |
|
56 |
|
57 // own simple |
54 // own simple |
58 #include "simplesipconnection.h" |
55 #include "simplesipconnection.h" |
59 #include "simplesipconnectionobserver.h" |
56 #include "simplesipconnectionobserver.h" |
60 #include "simplesipprofileobserver.h" |
57 #include "simplesipprofileobserver.h" |
61 #include "simplerefreshtimer.h" |
58 #include "simplerefreshtimer.h" |
81 _LIT8 ( KSimpleTimeout, "timeout" ); |
78 _LIT8 ( KSimpleTimeout, "timeout" ); |
82 _LIT8 ( KSimpleGiveup, "giveup" ); |
79 _LIT8 ( KSimpleGiveup, "giveup" ); |
83 _LIT8 ( KSimpleNoresource, "Noresource" ); |
80 _LIT8 ( KSimpleNoresource, "Noresource" ); |
84 _LIT8 ( KSipPrefix, "sip:" ); |
81 _LIT8 ( KSipPrefix, "sip:" ); |
85 |
82 |
|
83 // UID given for CSIP class. SIP Utils listens to new SIP requests |
|
84 // (when receiving IM) outside SIP dialogs. |
|
85 const TUid KSimpleSIPUtilsUID = { 0x10281EEC }; |
|
86 |
86 // ================= MEMBER FUNCTIONS ======================= |
87 // ================= MEMBER FUNCTIONS ======================= |
87 // |
88 // |
88 |
89 |
89 // ---------------------------------------------------------- |
90 // ---------------------------------------------------------- |
90 // CSimpleSipConnection::CSimpleSipConnection |
91 // CSimpleSipConnection::CSimpleSipConnection |
138 { |
138 { |
139 #ifdef _DEBUG |
139 #ifdef _DEBUG |
140 TSimpleLogger::Log( |
140 TSimpleLogger::Log( |
141 _L("SipConnection: ConstructL 20-01-07 this=%d" ), (TInt)this ); |
141 _L("SipConnection: ConstructL 20-01-07 this=%d" ), (TInt)this ); |
142 #endif |
142 #endif |
143 |
143 // initialize members |
|
144 iSip = CSIP::NewL( KSimpleSIPUtilsUID, *this ); |
144 iConnectionObserver = CSimpleSipConnectionObserver::NewL( *this); |
145 iConnectionObserver = CSimpleSipConnectionObserver::NewL( *this); |
|
146 iProfileObserver = |
|
147 CSimpleSipProfileObserver::NewL( iSip, *iConnectionObserver); |
145 SIPStrings::OpenL(); |
148 SIPStrings::OpenL(); |
146 // read static cenrep settings |
149 // read static cenrep settings |
147 iSettings.ReadCentRepSettings(); |
150 iSettings.ReadCentRepSettings(); |
148 |
151 |
149 #ifdef _DEBUG |
152 #ifdef _DEBUG |
440 HBufC8* temp = HBufC8::NewLC( KSipPrefix().Length() + |
443 HBufC8* temp = HBufC8::NewLC( KSipPrefix().Length() + |
441 aReq.Recipient().Length() ); // CS: 2 |
444 aReq.Recipient().Length() ); // CS: 2 |
442 temp->Des().Copy( KSipPrefix() ); |
445 temp->Des().Copy( KSipPrefix() ); |
443 temp->Des().Append( aReq.Recipient() ); |
446 temp->Des().Append( aReq.Recipient() ); |
444 User::LeaveIfError( parser.Parse( *temp )); |
447 User::LeaveIfError( parser.Parse( *temp )); |
445 CUri8* uri = CUri8::NewL( parser ); |
448 CUri8* uri = CUri8::NewLC( parser ); // CS: 3 |
446 |
449 |
447 // Start to fill header, Remote URI |
450 // Start to fill header, Remote URI |
448 CSIPRequestElements* elems = CSIPRequestElements::NewL( uri ); |
451 CSIPRequestElements* elems = CSIPRequestElements::NewL( uri ); |
|
452 CleanupStack::Pop( uri ); // ownership given to elems // CS: 2 |
449 CleanupStack::PushL( elems ); // CS: 3 |
453 CleanupStack::PushL( elems ); // CS: 3 |
450 |
454 |
451 TUriParser8 parser3; |
455 TUriParser8 parser3; |
452 User::LeaveIfError( parser3.Parse( iProfileObserver-> |
456 User::LeaveIfError( parser3.Parse( iProfileObserver-> |
453 GiveUserAorL() )); |
457 GiveUserAorL() )); |
454 uri = CUri8::NewL( parser3 ); |
458 uri = CUri8::NewLC( parser3 ); // CS: 4 |
|
459 |
455 CSIPAddress* sipAddress = CSIPAddress::NewL( uri ); |
460 CSIPAddress* sipAddress = CSIPAddress::NewL( uri ); |
|
461 CleanupStack::Pop( uri ); // ownership given to sipAddress // CS: 3 |
|
462 CleanupStack::PushL( sipAddress ); // CS: 4 |
456 |
463 |
457 // From Header |
464 // From Header |
458 CSIPFromHeader* fromH = CSIPFromHeader::NewL( sipAddress ); |
465 CSIPFromHeader* fromH = CSIPFromHeader::NewL( sipAddress ); |
459 elems->SetFromHeaderL( fromH ); // fromH, ownership given to elems |
466 CleanupStack::Pop( sipAddress ); // ownership given to FromH // CS: 3 |
|
467 CleanupStack::PushL( fromH ); // CS: 4 |
|
468 elems->SetFromHeaderL( fromH ); |
|
469 // fromH, ownership given to elems |
|
470 CleanupStack::Pop( fromH ); // CS: 3 |
460 |
471 |
461 uri = CUri8::NewL( parser ); |
472 uri = CUri8::NewLC( parser ); // CS: 4 |
|
473 |
462 CSIPAddress* addr = CSIPAddress::NewL( uri ); |
474 CSIPAddress* addr = CSIPAddress::NewL( uri ); |
|
475 CleanupStack::Pop( uri ); // CS: 3 |
|
476 CleanupStack::PushL( addr ); // CS: 4 |
|
477 |
463 // To Header |
478 // To Header |
464 CSIPToHeader* toHeader = CSIPToHeader::NewL( addr ); |
479 CSIPToHeader* toHeader = CSIPToHeader::NewL( addr ); |
|
480 CleanupStack::Pop( addr ); // CS: 3 |
|
481 CleanupStack::PushL( toHeader ); // CS: 4 |
465 elems->SetToHeaderL( toHeader ); |
482 elems->SetToHeaderL( toHeader ); |
|
483 CleanupStack::Pop( toHeader ); // CS: 3 |
466 |
484 |
467 CSIPMessageElements& mesElems = elems->MessageElements(); |
485 CSIPMessageElements& mesElems = elems->MessageElements(); |
468 |
486 |
469 // Add Expires Header |
487 // Add Expires Header |
470 if ( aReq.RefreshTime() ) |
488 if ( aReq.RefreshTime() ) |
478 User::LeaveIfError( headers.Append( exprH ) ); |
496 User::LeaveIfError( headers.Append( exprH ) ); |
479 CleanupStack::Pop( exprH ); // CS: 4 |
497 CleanupStack::Pop( exprH ); // CS: 4 |
480 |
498 |
481 mesElems.SetUserHeadersL( headers ); |
499 mesElems.SetUserHeadersL( headers ); |
482 // headers ownership given to mesElems |
500 // headers ownership given to mesElems |
483 CleanupStack::Pop( &headers ); // CS: 3 |
501 CleanupStack::Pop( &headers ); // CS: 3 |
484 } |
502 } |
485 |
503 |
486 // Set content type and content |
504 // Set content type and content |
487 HBufC8* buffer = aContent.AllocLC(); // CS: 4 |
505 CSIPContentTypeHeader* contTypeH = CSIPContentTypeHeader::NewLC( |
488 CSIPContentTypeHeader* contTypeH = CSIPContentTypeHeader::NewL( |
506 KSimpleMediaType, KSimpleMediaSubType ); // CS: 4 |
489 KSimpleMediaType, KSimpleMediaSubType ); |
507 HBufC8* buffer = aContent.AllocLC(); // CS: 5 |
490 CleanupStack::Pop( buffer ); // CS: 3 |
|
491 mesElems.SetContentL( buffer, contTypeH ); |
508 mesElems.SetContentL( buffer, contTypeH ); |
492 // buffer ownership given to mesElems |
509 // buffer ownership given to mesElems |
|
510 CleanupStack::Pop( buffer ); // CS: 4 |
493 // contTypeH ownership given to mesElems |
511 // contTypeH ownership given to mesElems |
|
512 CleanupStack::Pop( contTypeH ); // CS: 3 |
494 |
513 |
495 // Set method |
514 // Set method |
496 elems->SetMethodL( SIPStrings::StringF( SipStrConsts::EMessage ) ); |
515 elems->SetMethodL( SIPStrings::StringF( SipStrConsts::EMessage ) ); |
497 |
516 |
498 CleanupStack::Pop( elems ); // CS: 2 |
|
499 // Send the request transaction |
517 // Send the request transaction |
500 // elems, ownership given |
|
501 CSIPClientTransaction* sipTrans = iSipConnection->SendRequestL( elems, |
518 CSIPClientTransaction* sipTrans = iSipConnection->SendRequestL( elems, |
502 *regContext ); |
519 *regContext ); |
503 |
520 |
504 // Save SIP client transaction |
521 // Save SIP client transaction |
505 request->SetTransaction( sipTrans ); |
522 request->SetTransaction( sipTrans ); |
506 |
523 CleanupStack::Pop( elems ); // elems, ownership given // CS: 2 |
507 CleanupStack::PopAndDestroy( temp ); // CS: 1 |
524 CleanupStack::PopAndDestroy( temp ); // CS: 1 |
508 |
525 |
509 // Start refresh timer, it's used for garbage collection too. |
526 // Start refresh timer, it's used for garbage collection too. |
510 request->StartRefreshTimer(); |
527 request->StartRefreshTimer(); |
511 } |
528 } |
1073 |
1090 |
1074 acceH = CSIPAcceptHeader::NewLC( |
1091 acceH = CSIPAcceptHeader::NewLC( |
1075 KSimpleMultiType, KSimpleMultipartSubType ); |
1092 KSimpleMultiType, KSimpleMultipartSubType ); |
1076 User::LeaveIfError( headers.Append( acceH )); |
1093 User::LeaveIfError( headers.Append( acceH )); |
1077 ++popCount; |
1094 ++popCount; |
1078 |
|
1079 // add supported header with value eventlist |
|
1080 RPointerArray<CSIPSupportedHeader> suppHs = |
|
1081 CSIPSupportedHeader::DecodeL( KSimpleEventlist); |
|
1082 for( TInt count=0; count < suppHs.Count(); count++ ) |
|
1083 { |
|
1084 User::LeaveIfError( headers.Append( suppHs[count] )); |
|
1085 } |
|
1086 suppHs.Close(); |
|
1087 } |
1095 } |
1088 if ( r->Match( CSimpleRequest::EReqSubscribeWinfo )) |
1096 if ( r->Match( CSimpleRequest::EReqSubscribeWinfo )) |
1089 { |
1097 { |
1090 acceH = CSIPAcceptHeader::NewLC( |
1098 acceH = CSIPAcceptHeader::NewLC( |
1091 KSimpleApplicationType, KSimpleWinfoSubType ); |
1099 KSimpleApplicationType, KSimpleWinfoSubType ); |
1261 // memory for heap descriptors in DoHandleReceivedMessageL |
1269 // memory for heap descriptors in DoHandleReceivedMessageL |
1262 return error; |
1270 return error; |
1263 } |
1271 } |
1264 |
1272 |
1265 // ---------------------------------------------------------- |
1273 // ---------------------------------------------------------- |
1266 // CSimpleSipConnection::ConnectionChanged |
|
1267 // ---------------------------------------------------------- |
|
1268 // |
|
1269 void CSimpleSipConnection::ConnectionChanged() |
|
1270 { |
|
1271 #ifdef _DEBUG |
|
1272 TSimpleLogger::Log(_L("SipConnection: ConnectionChanged")); |
|
1273 if( iSipConnection ) |
|
1274 { |
|
1275 TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : old conn state %d (internal:%d)"), iSipConnection->State(), iSipState ); |
|
1276 TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : old IAP %d"), iSipConnection->IapId() ); |
|
1277 } |
|
1278 #endif |
|
1279 |
|
1280 iCurrentNbrSubs = 0; |
|
1281 CSIPConnection* conn = NULL; |
|
1282 TRAPD( err, conn = iProfileObserver->GiveConnectionL() ); |
|
1283 if( !err ) |
|
1284 { |
|
1285 delete iSipConnection; |
|
1286 iSipConnection = conn; |
|
1287 #ifdef _DEBUG |
|
1288 TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : new conn state %d"), iSipConnection->State() ); |
|
1289 TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : new IAP %d"), iSipConnection->IapId() ); |
|
1290 #endif |
|
1291 } |
|
1292 #ifdef _DEBUG |
|
1293 else |
|
1294 { |
|
1295 TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : Get SIP connection error %d"), err ); |
|
1296 } |
|
1297 #endif |
|
1298 |
|
1299 if( iSipConnection ) |
|
1300 { |
|
1301 if( iSipState != iSipConnection->State() ) |
|
1302 { |
|
1303 iConnectionObserver->ConnectionStateChanged( iSipConnection->State() ); |
|
1304 } |
|
1305 } |
|
1306 } |
|
1307 |
|
1308 // ---------------------------------------------------------- |
|
1309 // CSimpleSipConnection::StartToCheckExpiryL |
1274 // CSimpleSipConnection::StartToCheckExpiryL |
1310 // ---------------------------------------------------------- |
1275 // ---------------------------------------------------------- |
1311 // |
1276 // |
1312 void CSimpleSipConnection::StartToCheckExpiryL( CSimpleRequest& aReq ) |
1277 void CSimpleSipConnection::StartToCheckExpiryL( CSimpleRequest& aReq ) |
1313 { |
1278 { |
1404 |
1369 |
1405 while ( rIter ) |
1370 while ( rIter ) |
1406 { |
1371 { |
1407 CSimpleRequest* req = rIter; |
1372 CSimpleRequest* req = rIter; |
1408 rIter++; //lint !e1757 |
1373 rIter++; //lint !e1757 |
1409 |
1374 req->Destroy(); |
1410 // open request EReqReceiveIM should not be deleted |
|
1411 // will be deleted only when im message received |
|
1412 // or destructor is called. |
|
1413 if ( !req->Match( CSimpleRequest::EReqReceiveIM ) ) |
|
1414 { |
|
1415 req->Destroy(); |
|
1416 } |
|
1417 } |
|
1418 } |
|
1419 |
|
1420 // ----------------------------------------------------------------------------- |
|
1421 // CSimpleSipConnection::DeleteRequests |
|
1422 // ----------------------------------------------------------------------------- |
|
1423 void CSimpleSipConnection::DeleteRequests( |
|
1424 CSimpleRequest::TSimpleSipReqType aRequestType ) |
|
1425 { |
|
1426 #ifdef _DEBUG |
|
1427 TSimpleLogger::Log(_L("SipConnection: DeleteRequests type=%d" ), |
|
1428 aRequestType ); |
|
1429 #endif |
|
1430 // Delete buffered transaction requests match to the aRequestType |
|
1431 TDblQueIter<CSimpleRequest> rIter( iRequestList ); |
|
1432 rIter.SetToFirst(); |
|
1433 |
|
1434 while ( rIter ) |
|
1435 { |
|
1436 CSimpleRequest* req = rIter; |
|
1437 rIter++; //lint !e1757 |
|
1438 |
|
1439 if ( req->Match( aRequestType ) ) |
|
1440 { |
|
1441 req->Destroy(); |
|
1442 } |
|
1443 } |
1375 } |
1444 } |
1376 } |
1445 |
1377 |
1446 // ----------------------------------------------------------------------------- |
1378 // ----------------------------------------------------------------------------- |
1447 // CSimpleSipConnection::DeleteRequest |
1379 // CSimpleSipConnection::DeleteRequest |
1744 if ( header->Name() == extensionName ) |
1676 if ( header->Name() == extensionName ) |
1745 { |
1677 { |
1746 HBufC8* hValue = header->ToTextValueL(); |
1678 HBufC8* hValue = header->ToTextValueL(); |
1747 // hValue ownership is transferred |
1679 // hValue ownership is transferred |
1748 aReq->SetETag( hValue ); |
1680 aReq->SetETag( hValue ); |
1749 // store etag to vimpstsettingstore |
|
1750 StoreETagL( *hValue ); |
|
1751 ETagReceived = ETrue; |
1681 ETagReceived = ETrue; |
1752 } |
1682 } |
1753 else if ( header->Name() == SIPStrings::StringF( SipStrConsts::EExpiresHeader)) |
1683 else if ( header->Name() == SIPStrings::StringF( SipStrConsts::EExpiresHeader)) |
1754 { |
1684 { |
1755 // Save the new refresh time. |
1685 // Save the new refresh time. |
1765 } |
1695 } |
1766 if ( !ETagReceived || !aReq->RefreshTime() ) |
1696 if ( !ETagReceived || !aReq->RefreshTime() ) |
1767 { |
1697 { |
1768 // Remove old ETag if nore received or if the expires header was 0 in our request. |
1698 // Remove old ETag if nore received or if the expires header was 0 in our request. |
1769 aReq->SetETag( NULL ); |
1699 aReq->SetETag( NULL ); |
1770 //TPtrC8 nullETag = nullETag.Alloc( KNullDesC8 ); |
|
1771 TBufC8<1> nullETag( KNullDesC8 ); |
|
1772 HBufC8* buf; |
|
1773 buf = nullETag.Alloc(); |
|
1774 StoreETagL( *buf ); |
|
1775 delete buf; |
|
1776 } |
1700 } |
1777 // PopAndDestroy calls extensionName.Close() |
1701 // PopAndDestroy calls extensionName.Close() |
1778 CleanupStack::PopAndDestroy( &extensionName ); |
1702 CleanupStack::PopAndDestroy( &extensionName ); |
1779 } |
1703 } |
1780 |
1704 |
2146 #ifdef _DEBUG |
2070 #ifdef _DEBUG |
2147 TSimpleLogger::Log(_L("SipConnection: RegisterAnyL" )); |
2071 TSimpleLogger::Log(_L("SipConnection: RegisterAnyL" )); |
2148 #endif |
2072 #endif |
2149 |
2073 |
2150 iSettings.ReadOTASettingsL( aReq.Aux() ); |
2074 iSettings.ReadOTASettingsL( aReq.Aux() ); |
2151 |
2075 |
2152 TInt32 uniqueId = iSettings.SipProfileId(); |
|
2153 TUid uniqueUid; |
|
2154 uniqueUid.iUid = uniqueId; |
|
2155 |
|
2156 if ( !iSip && !iProfileObserver ) |
|
2157 { |
|
2158 iSip = CSIP::NewL( uniqueUid, *this ); |
|
2159 |
|
2160 iProfileObserver = CSimpleSipProfileObserver::NewL( |
|
2161 iSip, *iConnectionObserver); |
|
2162 } |
|
2163 |
|
2164 iProfileObserver->RegisterGivenProfileL( iSettings.SipProfileId() ); |
2076 iProfileObserver->RegisterGivenProfileL( iSettings.SipProfileId() ); |
2165 SetSipState( ESimpleSipIdle ); |
2077 SetSipState( ESimpleSipIdle ); |
2166 TRAPD( err, iSipConnection = iProfileObserver->GiveConnectionL() ); |
2078 TRAPD( err, iSipConnection = iProfileObserver->GiveConnectionL() ); |
2167 if ( !err ) |
2079 if ( !err ) |
2168 { |
2080 { |
2665 TSimpleLogger::Log( _L( |
2577 TSimpleLogger::Log( _L( |
2666 "CSimpleSipConnection::DoHandleReceivedMessageL - End" ) ); |
2578 "CSimpleSipConnection::DoHandleReceivedMessageL - End" ) ); |
2667 #endif |
2579 #endif |
2668 } |
2580 } |
2669 |
2581 |
2670 // ----------------------------------------------------------------------------- |
|
2671 // CSimpleRequest::SetServiceId |
|
2672 // ----------------------------------------------------------------------------- |
|
2673 EXPORT_C void CSimpleSipConnection::SetServiceId( TInt32 aServiceId ) |
|
2674 { |
|
2675 #ifdef _DEBUG |
|
2676 TSimpleLogger::Log( _L( |
|
2677 "CSimpleSipConnection::SetServiceId old serviceId = %d, new serviceId = %d" ), |
|
2678 iServiceId, aServiceId ); |
|
2679 #endif |
|
2680 iServiceId = aServiceId; |
|
2681 } |
|
2682 |
|
2683 // ----------------------------------------------------------------------------- |
|
2684 // CSimpleRequest::StoreETag |
|
2685 // ----------------------------------------------------------------------------- |
|
2686 void CSimpleSipConnection::StoreETagL( HBufC8& aETag ) |
|
2687 { |
|
2688 #ifdef _DEBUG |
|
2689 TBuf<255> printDocumentId; |
|
2690 printDocumentId.Copy( aETag ); |
|
2691 TSimpleLogger::Log(_L("CSimpleSipConnection: StoreETag ETag = %S, serviceId = %d" ), |
|
2692 &printDocumentId, iServiceId ); |
|
2693 #endif |
|
2694 MVIMPSTSettingsStore* settings = CVIMPSTSettingsStore::NewLC(); |
|
2695 |
|
2696 // Store ETag to uiservicetabsettings |
|
2697 User::LeaveIfError( settings->SetL( |
|
2698 iServiceId, EServicePresenceSessionIdentifier, aETag ) ); |
|
2699 |
|
2700 CleanupStack::PopAndDestroy(); //settings |
|
2701 } |
|
2702 |
|