realtimenetprots/sipfw/ClientResolver/Resolver/src/CSipAllowEventsStrategy.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : CSipAllowEventsStrategy.cpp
       
    15 // Part of       : SIP Client Resolver
       
    16 // Version       : 1.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "CSipAllowEventsStrategy.h"
       
    22 #include "MSipClients.h"
       
    23 #include "MSipClient.h"
       
    24 #include "sipresponse.h"
       
    25 #include "siprequest.h"
       
    26 #include "sipalloweventsheader.h"
       
    27 #include "sipeventheader.h"
       
    28 #include "sipstrings.h"
       
    29 #include "sipstrconsts.h"
       
    30 #include "SIPCRLogs.h"
       
    31 
       
    32 const TUint K489ResponseCode = 489;
       
    33 
       
    34 
       
    35 // ----------------------------------------------------------------------------
       
    36 // CSipAllowEventsStrategy::NewL
       
    37 // ----------------------------------------------------------------------------
       
    38 //
       
    39 CSipAllowEventsStrategy* CSipAllowEventsStrategy::NewL(
       
    40     MSipClients& aSipClients,
       
    41     CSipHeaderStrategyBase* aNextStrategy,
       
    42     CSipHeaderStrategyBase* aNextStrategy2 )
       
    43 	{
       
    44 	CSipAllowEventsStrategy* self = 
       
    45 		CSipAllowEventsStrategy::NewLC( aSipClients,
       
    46 										aNextStrategy,
       
    47 										aNextStrategy2 );
       
    48 	CleanupStack::Pop( self );
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CSipAllowEventsStrategy::NewLC
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CSipAllowEventsStrategy* CSipAllowEventsStrategy::NewLC(
       
    57     MSipClients& aSipClients,
       
    58     CSipHeaderStrategyBase* aNextStrategy,
       
    59     CSipHeaderStrategyBase* aNextStrategy2 )
       
    60 	{
       
    61 	CSipAllowEventsStrategy* self = 
       
    62 		new(ELeave)CSipAllowEventsStrategy( aSipClients,
       
    63 											aNextStrategy,
       
    64 											aNextStrategy2 );
       
    65 	CleanupStack::PushL( self );
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 // ----------------------------------------------------------------------------
       
    70 // CSipAllowEventsStrategy::CSipAllowEventsStrategy
       
    71 // ----------------------------------------------------------------------------
       
    72 //
       
    73 CSipAllowEventsStrategy::CSipAllowEventsStrategy(
       
    74     MSipClients& aSipClients,
       
    75     CSipHeaderStrategyBase* aNextStrategy,
       
    76     CSipHeaderStrategyBase* aNextStrategy2 ) 
       
    77  : CSipHeaderStrategyBase( aSipClients,aNextStrategy,aNextStrategy2 )
       
    78 	{
       
    79     iEventHeaderName = SIPStrings::StringF( SipStrConsts::EEventHeader );
       
    80     iAllowEventsHeaderName = 
       
    81         SIPStrings::StringF( SipStrConsts::EAllowEventsHeader );
       
    82 	}
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CSipAllowEventsStrategy::~CSipAllowEventsStrategy
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CSipAllowEventsStrategy::~CSipAllowEventsStrategy ()
       
    89 	{
       
    90 	}
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // CSipAllowEventsStrategy::ApplyL
       
    94 // ----------------------------------------------------------------------------
       
    95 //
       
    96 CSIPResponse* CSipAllowEventsStrategy::ApplyL(
       
    97     CSIPRequest& aRequest, 
       
    98     RArray<TUid>& aUids,
       
    99     TBool& aContinueSearch,
       
   100     CSIPClientResolver2& aClientResolver2 )
       
   101 	{
       
   102 	SIP_CR_LOG("CSipAllowEventsStrategy::ApplyL")
       
   103 	CSIPResponse* response = NULL;
       
   104     // If the request does not contain Event-header skip the strategy.
       
   105 	if ( aRequest.HasHeader( iEventHeaderName ) )
       
   106         {
       
   107         response = MatchClientsL( aRequest,aUids );
       
   108         if ( ( response && response->ResponseCode() == K489ResponseCode ) &&
       
   109         	    iNextStrategy2 )
       
   110         	{
       
   111         	delete response;
       
   112         	response = NULL;
       
   113         	response = iNextStrategy2->ApplyL( aRequest,aUids,aContinueSearch,
       
   114         									   aClientResolver2 );
       
   115         	}
       
   116         }
       
   117     else
       
   118         {
       
   119         if ( iNextStrategy )
       
   120             {
       
   121             response = iNextStrategy->ApplyL( aRequest,aUids,aContinueSearch,
       
   122             								  aClientResolver2 );
       
   123             }    
       
   124         }
       
   125     return response;
       
   126 	}
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // CSipAllowEventsStrategy::CreateResponseL
       
   130 // ----------------------------------------------------------------------------
       
   131 //
       
   132 CSIPResponse* CSipAllowEventsStrategy::CreateResponseL()
       
   133     {
       
   134     return CSIPResponse::NewL( K489ResponseCode,
       
   135         SIPStrings::StringF( SipStrConsts::EPhraseBadEvent ) );
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------------------------------
       
   139 // CSipAllowEventsStrategy::CompareHeaders
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 TBool CSipAllowEventsStrategy::CompareHeaders(
       
   143     CSIPRequest& aRequest,
       
   144     MSipClient& aClient )
       
   145 	{
       
   146 	CSIPHeaderBase* header = aRequest.Header( iEventHeaderName,0 );
       
   147 	if ( header )
       
   148 	    {
       
   149 	    CSIPEventHeader* eventHeader = static_cast<CSIPEventHeader*>(header);
       
   150 	    TPtrC8 eventPackage(eventHeader->EventPackage());
       
   151 	    RPointerArray<CSIPHeaderBase>& clientHeaders = aClient.SIPHeaders();
       
   152 	
       
   153 	    for(TInt i=0; i < clientHeaders.Count(); i++)
       
   154 		    {
       
   155             if (clientHeaders[i]->Name() == iAllowEventsHeaderName)
       
   156                 {
       
   157                 CSIPAllowEventsHeader* clientHeader = 
       
   158                     static_cast<CSIPAllowEventsHeader*>(clientHeaders[i]);
       
   159                 if (eventPackage.Compare(clientHeader->EventPackage()) == 0)
       
   160                     {
       
   161                     return ETrue;
       
   162                     }
       
   163                 }
       
   164 		    }	    
       
   165 	    }
       
   166 
       
   167 	return EFalse;
       
   168 	}