simpleengine/siputils/src/simplesipconnection.cpp
branchRCL_3
changeset 18 fbd2e7cec7ef
parent 17 2669f8761a99
--- a/simpleengine/siputils/src/simplesipconnection.cpp	Tue Aug 31 15:35:50 2010 +0300
+++ b/simpleengine/siputils/src/simplesipconnection.cpp	Wed Sep 01 12:23:14 2010 +0100
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2006-2009 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,6 +36,7 @@
 #include <siprefresh.h>
 #include <sipmessageelements.h>
 #include <sipsubscribedialogassoc.h>
+#include <sipregistrationcontext.h>
 
 // sip codec api
 #include <sipfromheader.h>
@@ -51,6 +52,8 @@
 #include <sipsupportedheader.h>
 #include <sipacceptheader.h>
 
+#include <cvimpstsettingsstore.h>
+
 // own simple
 #include "simplesipconnection.h"
 #include "simplesipconnectionobserver.h"
@@ -80,10 +83,6 @@
 _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 =======================
 //
 
@@ -114,6 +113,7 @@
     delete iConnectionObserver;
     delete iSip;
     DeleteRequests();
+    DeleteRequests( CSimpleRequest::EReqReceiveIM );
     SIPStrings::Close();
     }
 
@@ -140,11 +140,8 @@
     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();
@@ -450,36 +447,22 @@
         // 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::NewLC( parser3 );  // CS: 4
-        
+        uri = CUri8::NewL( parser3 );
         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 );
-        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
+        elems->SetFromHeaderL( fromH ); // fromH, ownership given to elems
         
-        uri = CUri8::NewLC( parser );  // CS: 4
-        
+        uri = CUri8::NewL( parser );
         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();
         
@@ -497,29 +480,30 @@
             
             mesElems.SetUserHeadersL( headers );
             // headers ownership given to mesElems
-            CleanupStack::Pop( &headers ); // CS: 3            
+            CleanupStack::Pop( &headers ); // CS: 3
             }
         
         // Set content type and content
-        CSIPContentTypeHeader* contTypeH = CSIPContentTypeHeader::NewLC(
-            KSimpleMediaType, KSimpleMediaSubType );  // CS: 4
-        HBufC8* buffer = aContent.AllocLC();  // CS: 5
+        HBufC8* buffer = aContent.AllocLC(); // CS: 4
+        CSIPContentTypeHeader* contTypeH = CSIPContentTypeHeader::NewL(
+            KSimpleMediaType, KSimpleMediaSubType );
+        CleanupStack::Pop( buffer ); // CS: 3
         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.
@@ -1091,6 +1075,15 @@
             KSimpleMultiType, KSimpleMultipartSubType );
         User::LeaveIfError( headers.Append( acceH ));
         ++popCount;
+
+        // add supported header with value eventlist
+        RPointerArray<CSIPSupportedHeader> 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 ))
         {
@@ -1270,6 +1263,49 @@
     }
 
 // ----------------------------------------------------------
+// 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
 // ----------------------------------------------------------
 //
@@ -1370,7 +1406,40 @@
         {
         CSimpleRequest* req = rIter;
         rIter++; //lint !e1757
-        req->Destroy();
+        
+        // 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<CSimpleRequest> rIter( iRequestList );
+    rIter.SetToFirst();
+
+    while ( rIter )
+        {
+        CSimpleRequest* req = rIter;
+        rIter++; //lint !e1757
+        
+        if ( req->Match( aRequestType ) )
+            {
+            req->Destroy();
+            }
         }
     }
 
@@ -1676,6 +1745,8 @@
             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))
@@ -1695,6 +1766,12 @@
         {
         // 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 );
@@ -2070,7 +2147,19 @@
 #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() );
@@ -2539,11 +2628,9 @@
     {
     if ( aState == ESimpleSipActive )
         {
-        // Check that both SIP Profile and SIP connection are ready.
+        // Check that SIP Profile is ready.
         // iProfileObserver is created in ConstructL.
-        if ( iProfileObserver->IsProfileActive() && 
-             iSipConnection &&
-             iSipConnection->State() == CSIPConnection::EActive )
+        if ( iProfileObserver->IsProfileActive() )
             {
             SetSipState( aState );            
             }
@@ -2577,3 +2664,36 @@
 #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   
+    }
+