mmsharing/mmshavailability/src/musavacapabilitysipagent.cpp
changeset 0 f0cf47e981f9
child 31 33a5d2bbf6fc
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:   SIP event handling class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "musavacapabilitysipagent.h"
       
    20 #include <e32svr.h>
       
    21 #include <rconnmon.h>
       
    22 #include <sipdialog.h>
       
    23 #include <sipservertransaction.h>
       
    24 #include <sipclienttransaction.h>
       
    25 #include <sipdialogassocbase.h>
       
    26 #include <sipinvitedialogassoc.h>
       
    27 #include <sipregistrationbinding.h>
       
    28 #include <siprefresh.h>
       
    29 #include <sipstrings.h>
       
    30 #include <sipstrconsts.h>
       
    31 #include <sipresponseelements.h>
       
    32 
       
    33 #include "muslogger.h"
       
    34 #include "musavacapabilityexchange.h"
       
    35 #include "musavacapabilityquery.h"
       
    36 #include "musavaterminal.h"
       
    37 #include "musavasharedobject.h"
       
    38 #include "musavasip.h"
       
    39 #include "musavacapabilitycontext.h"
       
    40 #include "mmusavacapabilityqueryobserver.h"
       
    41 
       
    42 // --------------------------------------------------------------------------
       
    43 // C++ constructor
       
    44 // --------------------------------------------------------------------------
       
    45 //
       
    46 CMusAvaCapabilitySipAgent::CMusAvaCapabilitySipAgent( 
       
    47                             CMusAvaCapabilityExchange& aCapabilityExchange,
       
    48                             CMusAvaSharedObject& aSharedObject,
       
    49                             MMusAvaAvailabilityObserver& aAvaObserver)
       
    50     : iCapabilityExchange( aCapabilityExchange ),
       
    51       iSharedObj( aSharedObject ),
       
    52       iAvailabilityObserver( aAvaObserver )
       
    53     {
       
    54     }
       
    55 
       
    56 
       
    57 // --------------------------------------------------------------------------
       
    58 // Symbian two-phase constructor
       
    59 // --------------------------------------------------------------------------
       
    60 //
       
    61 CMusAvaCapabilitySipAgent* CMusAvaCapabilitySipAgent::NewL( 
       
    62                             CMusAvaCapabilityExchange& aCapabilityExchange,
       
    63                             CMusAvaSharedObject& aSharedObject,
       
    64                             MMusAvaAvailabilityObserver& aAvaObserver)
       
    65     {
       
    66     MUS_LOG( "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent::NewL" )
       
    67     CMusAvaCapabilitySipAgent* self = 
       
    68         new (ELeave) CMusAvaCapabilitySipAgent( aCapabilityExchange, 
       
    69                                                 aSharedObject,
       
    70                                                 aAvaObserver );
       
    71     MUS_LOG( "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent::NewL" )
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 // C++ destructor
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 CMusAvaCapabilitySipAgent::~CMusAvaCapabilitySipAgent()
       
    81     {
       
    82     MUS_LOG( 
       
    83     "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent::~CMusAvaCapabilitySipAgent" )
       
    84 
       
    85     delete iSipConnection;
       
    86     
       
    87     MUS_LOG( 
       
    88     "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent::~CMusAvaCapabilitySipAgent" )
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CMusAvaCapabilitySipAgent::ExecuteCapabilityQueryL
       
    93 // --------------------------------------------------------------------------
       
    94 // 
       
    95 void CMusAvaCapabilitySipAgent::ExecuteCapabilityQueryL( 
       
    96                                            CMusAvaCapability& aCapability, 
       
    97                                            const TDesC& aSipAddress )
       
    98     {
       
    99     MUS_LOG( 
       
   100     "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent::ExecuteCapabilityQueryL" )
       
   101 
       
   102     CSIPProfile* profile = iSharedObj.MusAvaSip().Profile();
       
   103     if ( !profile )
       
   104         {
       
   105         User::Leave( KErrNotFound );
       
   106         }
       
   107 
       
   108     // Fetching connection leaves if profile is not registered for some reason,
       
   109     // Thats what we want, forced creation of connection would activate PDP
       
   110     // context although there's no reason to do that without registration.
       
   111     CMusAvaCapabilityQuery* query = CMusAvaCapabilityQuery::NewL( 
       
   112                                         aCapability,
       
   113                                         *iSharedObj.MusAvaSip().ConnectionL( EFalse ), 
       
   114                                         *profile, 
       
   115                                         aSipAddress );
       
   116     
       
   117     CleanupStack::PushL( query );
       
   118     
       
   119     query->Terminal().ExecuteQueryL( query );
       
   120     
       
   121     CleanupStack::Pop( query );
       
   122     
       
   123     MUS_LOG( 
       
   124     "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent::ExecuteCapabilityQueryL" )
       
   125     }
       
   126 
       
   127 // --------------------------------------------------------------------------
       
   128 // From MSIPObserver, incoming SIP request outside dialog is handled here
       
   129 // already.
       
   130 // --------------------------------------------------------------------------
       
   131 //
       
   132 
       
   133 TInt CMusAvaCapabilitySipAgent::IncomingRequest( TUint32 /*aIapId*/,
       
   134                                     CSIPServerTransaction* /*aTransaction*/ )
       
   135     {
       
   136     MUS_LOG( 
       
   137         "mus: [MUSAVA]  -> CMusAvaCapabilitySipAgent::IncomingRequest()" )
       
   138     // If this method was called, there's no connection for this IAP
       
   139     MUS_LOG( "mus: [MUSAVA]  if this method was called,\
       
   140     	there's no capability" )
       
   141     MUS_LOG( 
       
   142         "mus: [MUSAVA]  <- CMusAvaCapabilitySipAgent::IncomingRequest()" )
       
   143     return KErrNotFound;
       
   144     }
       
   145 
       
   146 // -------------------------------------------------------------------------
       
   147 // SIP request timed-out and has been destroyed.
       
   148 // -------------------------------------------------------------------------
       
   149 //
       
   150 TInt CMusAvaCapabilitySipAgent::TimedOut(
       
   151                                     CSIPServerTransaction& /*aTransaction*/ )
       
   152     {
       
   153     MUS_LOG( "mus: [MUSAVA]  -> CMusAvaCapabilitySipAgent::ConstructL()" )
       
   154     MUS_LOG( "mus: [MUSAVA]  <- CMusAvaCapabilitySipAgent::ConstructL()" )
       
   155     return KErrNotSupported;
       
   156     }
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 //  A SIP request outside a dialog has been received from the network.
       
   160 // --------------------------------------------------------------------------
       
   161 //
       
   162 TInt CMusAvaCapabilitySipAgent::IncomingRequest(
       
   163                                         CSIPServerTransaction* aTransaction )
       
   164     {
       
   165     MUS_LOG( "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent::IncomingRequest" )
       
   166     TInt retval = KErrNone;
       
   167     if ( aTransaction->Type() == 
       
   168                         SIPStrings::StringF( SipStrConsts::EOptions ) )
       
   169         {  
       
   170         // Answer 200OK only when CS call remain at Availability States
       
   171         if ( MMusAvaObserver::EMusAvaStatusNotExecuted <= 
       
   172              iAvailabilityObserver.AvailabilityPluginState() )
       
   173             {
       
   174             retval = 
       
   175              iCapabilityExchange.QueryObserver().CapabilityQueryAnswered() ?
       
   176              KErrNotFound : KErrNone;
       
   177         
       
   178             if ( !retval )
       
   179                 {
       
   180                 MUS_LOG( "mus: [MUSAVA] Responding to OPTIONS" )
       
   181                 iCapabilityExchange.QueryReceived( aTransaction );
       
   182                 }
       
   183             }
       
   184         else
       
   185             {
       
   186             retval = KErrNotFound;
       
   187             }
       
   188         }
       
   189     else        
       
   190         {
       
   191         MUS_LOG( "mus: [MUSAVA] Default response" )
       
   192         TRAP_IGNORE( HandleIncomingRequestL( *aTransaction ) )
       
   193         delete aTransaction;
       
   194         MUS_LOG( "mus: [MUSAVA] Default response sent" )
       
   195         }
       
   196     MUS_LOG( "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent::IncomingRequest" )
       
   197     return retval;
       
   198     }
       
   199 
       
   200 // --------------------------------------------------------------------------
       
   201 // From MSIPConnectionObserver, incoming SIP request outside dialog is 
       
   202 // handled here already.
       
   203 // --------------------------------------------------------------------------
       
   204 //
       
   205 void CMusAvaCapabilitySipAgent::HandleIncomingRequestL( 
       
   206                                         CSIPServerTransaction& aTransaction )
       
   207     {
       
   208     MUS_LOG( 
       
   209     "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent::HandleIncomingRequestL" )
       
   210     RStringF phrase = 
       
   211                 SIPStrings::StringF( SipStrConsts::EPhraseNotImplemented );
       
   212     CSIPResponseElements* response = 
       
   213         CSIPResponseElements::NewLC( KMUSAVASIPNotImplemented, phrase );
       
   214     aTransaction.SendResponseL( response );
       
   215     CleanupStack::Pop( response );
       
   216     MUS_LOG( 
       
   217     "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent::HandleIncomingRequestL" )
       
   218     }
       
   219 
       
   220 // --------------------------------------------------------------------------
       
   221 // CMusAvaCapabilitySipAgent::IncomingResponse
       
   222 // --------------------------------------------------------------------------
       
   223 //
       
   224 TInt CMusAvaCapabilitySipAgent::IncomingResponse( 
       
   225                                         CSIPClientTransaction& aTransaction )
       
   226     {
       
   227     MUS_LOG( 
       
   228         "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent::IncomingResponse" )
       
   229     iCapabilityExchange.AnswerToQueryReceived( aTransaction );
       
   230     MUS_LOG( 
       
   231         "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent::IncomingResponse" )
       
   232     return KErrNone;
       
   233     }
       
   234     
       
   235 // --------------------------------------------------------------------------
       
   236 // CMusAvaCapabilitySipAgent::ErrorOccured
       
   237 // --------------------------------------------------------------------------
       
   238 //
       
   239 TInt CMusAvaCapabilitySipAgent::ErrorOccured( TInt aError,
       
   240                                         CSIPTransactionBase& aTransaction )
       
   241     {
       
   242     MUS_LOG( "mus: [MUSAVA] -> CMusAvaCapabilitySipAgent:.ErrorOccured" )
       
   243     
       
   244     if ( aTransaction.IsSIPClientTransaction() )
       
   245         {
       
   246         MUS_LOG( "mus: [MUSAVA] Canceling query" )
       
   247         
       
   248         iCapabilityExchange.CancelQuery( 
       
   249                 aError, 
       
   250                 static_cast<CSIPClientTransaction&>( aTransaction ) );
       
   251         }
       
   252     else
       
   253         {
       
   254         MUS_LOG( "mus: [MUSAVA] Server transaction, nothing to do" )
       
   255         }
       
   256         
       
   257     MUS_LOG( "mus: [MUSAVA] <- CMusAvaCapabilitySipAgent:.ErrorOccured" )
       
   258     return KErrNone;
       
   259     }
       
   260