diff -r 2580314736af -r 2669f8761a99 simpleengine/siputils/src/simplesipconnection.cpp --- a/simpleengine/siputils/src/simplesipconnection.cpp Thu Aug 19 10:19:02 2010 +0300 +++ b/simpleengine/siputils/src/simplesipconnection.cpp Tue Aug 31 15:35:50 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -36,7 +36,6 @@ #include #include #include -#include // sip codec api #include @@ -52,8 +51,6 @@ #include #include -#include - // own simple #include "simplesipconnection.h" #include "simplesipconnectionobserver.h" @@ -83,6 +80,10 @@ _LIT8 ( KSimpleNoresource, "Noresource" ); _LIT8 ( KSipPrefix, "sip:" ); +// UID given for CSIP class. SIP Utils listens to new SIP requests +// (when receiving IM) outside SIP dialogs. +const TUid KSimpleSIPUtilsUID = { 0x10281EEC }; + // ================= MEMBER FUNCTIONS ======================= // @@ -113,7 +114,6 @@ delete iConnectionObserver; delete iSip; DeleteRequests(); - DeleteRequests( CSimpleRequest::EReqReceiveIM ); SIPStrings::Close(); } @@ -140,8 +140,11 @@ TSimpleLogger::Log( _L("SipConnection: ConstructL 20-01-07 this=%d" ), (TInt)this ); #endif - + // initialize members + iSip = CSIP::NewL( KSimpleSIPUtilsUID, *this ); iConnectionObserver = CSimpleSipConnectionObserver::NewL( *this); + iProfileObserver = + CSimpleSipProfileObserver::NewL( iSip, *iConnectionObserver); SIPStrings::OpenL(); // read static cenrep settings iSettings.ReadCentRepSettings(); @@ -447,22 +450,36 @@ // Start to fill header, Remote URI CSIPRequestElements* elems = CSIPRequestElements::NewL( uri ); CleanupStack::PushL( elems ); // CS: 3 - + TUriParser8 parser3; User::LeaveIfError( parser3.Parse( iProfileObserver-> GiveUserAorL() )); - uri = CUri8::NewL( parser3 ); + uri = CUri8::NewLC( parser3 ); // CS: 4 + CSIPAddress* sipAddress = CSIPAddress::NewL( uri ); + CleanupStack::Pop( uri ); // ownership given to sipAddress // CS: 3 + CleanupStack::PushL( sipAddress ); // CS: 4 // From Header CSIPFromHeader* fromH = CSIPFromHeader::NewL( sipAddress ); - elems->SetFromHeaderL( fromH ); // fromH, ownership given to elems + CleanupStack::Pop( sipAddress ); // ownership given to FromH // CS: 3 + CleanupStack::PushL( fromH ); // CS: 4 + elems->SetFromHeaderL( fromH ); + // fromH, ownership given to elems + CleanupStack::Pop( fromH ); // CS: 3 - uri = CUri8::NewL( parser ); + uri = CUri8::NewLC( parser ); // CS: 4 + CSIPAddress* addr = CSIPAddress::NewL( uri ); + CleanupStack::Pop( uri ); // CS: 3 + CleanupStack::PushL( addr ); // CS: 4 + // To Header CSIPToHeader* toHeader = CSIPToHeader::NewL( addr ); + CleanupStack::Pop( addr ); // CS: 3 + CleanupStack::PushL( toHeader ); // CS: 4 elems->SetToHeaderL( toHeader ); + CleanupStack::Pop( toHeader ); // CS: 3 CSIPMessageElements& mesElems = elems->MessageElements(); @@ -480,30 +497,29 @@ mesElems.SetUserHeadersL( headers ); // headers ownership given to mesElems - CleanupStack::Pop( &headers ); // CS: 3 + CleanupStack::Pop( &headers ); // CS: 3 } // Set content type and content - HBufC8* buffer = aContent.AllocLC(); // CS: 4 - CSIPContentTypeHeader* contTypeH = CSIPContentTypeHeader::NewL( - KSimpleMediaType, KSimpleMediaSubType ); - CleanupStack::Pop( buffer ); // CS: 3 + CSIPContentTypeHeader* contTypeH = CSIPContentTypeHeader::NewLC( + KSimpleMediaType, KSimpleMediaSubType ); // CS: 4 + HBufC8* buffer = aContent.AllocLC(); // CS: 5 mesElems.SetContentL( buffer, contTypeH ); // buffer ownership given to mesElems + CleanupStack::Pop( buffer ); // CS: 4 // contTypeH ownership given to mesElems + CleanupStack::Pop( contTypeH ); // CS: 3 // Set method elems->SetMethodL( SIPStrings::StringF( SipStrConsts::EMessage ) ); - CleanupStack::Pop( elems ); // CS: 2 // Send the request transaction - // elems, ownership given CSIPClientTransaction* sipTrans = iSipConnection->SendRequestL( elems, *regContext ); // Save SIP client transaction request->SetTransaction( sipTrans ); - + CleanupStack::Pop( elems ); // elems, ownership given // CS: 2 CleanupStack::PopAndDestroy( temp ); // CS: 1 // Start refresh timer, it's used for garbage collection too. @@ -1075,15 +1091,6 @@ KSimpleMultiType, KSimpleMultipartSubType ); User::LeaveIfError( headers.Append( acceH )); ++popCount; - - // add supported header with value eventlist - RPointerArray suppHs = - CSIPSupportedHeader::DecodeL( KSimpleEventlist); - for( TInt count=0; count < suppHs.Count(); count++ ) - { - User::LeaveIfError( headers.Append( suppHs[count] )); - } - suppHs.Close(); } if ( r->Match( CSimpleRequest::EReqSubscribeWinfo )) { @@ -1263,49 +1270,6 @@ } // ---------------------------------------------------------- -// CSimpleSipConnection::ConnectionChanged -// ---------------------------------------------------------- -// -void CSimpleSipConnection::ConnectionChanged() - { -#ifdef _DEBUG - TSimpleLogger::Log(_L("SipConnection: ConnectionChanged")); - if( iSipConnection ) - { - TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : old conn state %d (internal:%d)"), iSipConnection->State(), iSipState ); - TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : old IAP %d"), iSipConnection->IapId() ); - } -#endif - - iCurrentNbrSubs = 0; - CSIPConnection* conn = NULL; - TRAPD( err, conn = iProfileObserver->GiveConnectionL() ); - if( !err ) - { - delete iSipConnection; - iSipConnection = conn; -#ifdef _DEBUG - TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : new conn state %d"), iSipConnection->State() ); - TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : new IAP %d"), iSipConnection->IapId() ); -#endif - } -#ifdef _DEBUG - else - { - TSimpleLogger::Log(_L("SipConnection: ConnectionChanged : Get SIP connection error %d"), err ); - } -#endif - - if( iSipConnection ) - { - if( iSipState != iSipConnection->State() ) - { - iConnectionObserver->ConnectionStateChanged( iSipConnection->State() ); - } - } - } - -// ---------------------------------------------------------- // CSimpleSipConnection::StartToCheckExpiryL // ---------------------------------------------------------- // @@ -1406,40 +1370,7 @@ { CSimpleRequest* req = rIter; rIter++; //lint !e1757 - - // open request EReqReceiveIM should not be deleted - // will be deleted only when im message received - // or destructor is called. - if ( !req->Match( CSimpleRequest::EReqReceiveIM ) ) - { - req->Destroy(); - } - } - } - -// ----------------------------------------------------------------------------- -// CSimpleSipConnection::DeleteRequests -// ----------------------------------------------------------------------------- -void CSimpleSipConnection::DeleteRequests( - CSimpleRequest::TSimpleSipReqType aRequestType ) - { -#ifdef _DEBUG - TSimpleLogger::Log(_L("SipConnection: DeleteRequests type=%d" ), - aRequestType ); -#endif - // Delete buffered transaction requests match to the aRequestType - TDblQueIter rIter( iRequestList ); - rIter.SetToFirst(); - - while ( rIter ) - { - CSimpleRequest* req = rIter; - rIter++; //lint !e1757 - - if ( req->Match( aRequestType ) ) - { - req->Destroy(); - } + req->Destroy(); } } @@ -1745,8 +1676,6 @@ HBufC8* hValue = header->ToTextValueL(); // hValue ownership is transferred aReq->SetETag( hValue ); - // store etag to vimpstsettingstore - StoreETagL( *hValue ); ETagReceived = ETrue; } else if ( header->Name() == SIPStrings::StringF( SipStrConsts::EExpiresHeader)) @@ -1766,12 +1695,6 @@ { // Remove old ETag if nore received or if the expires header was 0 in our request. aReq->SetETag( NULL ); - //TPtrC8 nullETag = nullETag.Alloc( KNullDesC8 ); - TBufC8<1> nullETag( KNullDesC8 ); - HBufC8* buf; - buf = nullETag.Alloc(); - StoreETagL( *buf ); - delete buf; } // PopAndDestroy calls extensionName.Close() CleanupStack::PopAndDestroy( &extensionName ); @@ -2147,19 +2070,7 @@ #endif iSettings.ReadOTASettingsL( aReq.Aux() ); - - TInt32 uniqueId = iSettings.SipProfileId(); - TUid uniqueUid; - uniqueUid.iUid = uniqueId; - - if ( !iSip && !iProfileObserver ) - { - iSip = CSIP::NewL( uniqueUid, *this ); - - iProfileObserver = CSimpleSipProfileObserver::NewL( - iSip, *iConnectionObserver); - } - + iProfileObserver->RegisterGivenProfileL( iSettings.SipProfileId() ); SetSipState( ESimpleSipIdle ); TRAPD( err, iSipConnection = iProfileObserver->GiveConnectionL() ); @@ -2628,9 +2539,11 @@ { if ( aState == ESimpleSipActive ) { - // Check that SIP Profile is ready. + // Check that both SIP Profile and SIP connection are ready. // iProfileObserver is created in ConstructL. - if ( iProfileObserver->IsProfileActive() ) + if ( iProfileObserver->IsProfileActive() && + iSipConnection && + iSipConnection->State() == CSIPConnection::EActive ) { SetSipState( aState ); } @@ -2664,36 +2577,3 @@ #endif } -// ----------------------------------------------------------------------------- -// CSimpleRequest::SetServiceId -// ----------------------------------------------------------------------------- -EXPORT_C void CSimpleSipConnection::SetServiceId( TInt32 aServiceId ) - { -#ifdef _DEBUG - TSimpleLogger::Log( _L( - "CSimpleSipConnection::SetServiceId old serviceId = %d, new serviceId = %d" ), - iServiceId, aServiceId ); -#endif - iServiceId = aServiceId; - } - -// ----------------------------------------------------------------------------- -// CSimpleRequest::StoreETag -// ----------------------------------------------------------------------------- -void CSimpleSipConnection::StoreETagL( HBufC8& aETag ) - { -#ifdef _DEBUG - TBuf<255> printDocumentId; - printDocumentId.Copy( aETag ); - TSimpleLogger::Log(_L("CSimpleSipConnection: StoreETag ETag = %S, serviceId = %d" ), - &printDocumentId, iServiceId ); -#endif - MVIMPSTSettingsStore* settings = CVIMPSTSettingsStore::NewLC(); - - // Store ETag to uiservicetabsettings - User::LeaveIfError( settings->SetL( - iServiceId, EServicePresenceSessionIdentifier, aETag ) ); - - CleanupStack::PopAndDestroy(); //settings - } -