realtimenetprots/sipfw/SIP/Dialogs/src/CSigCompMgr.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          : CSigCompMgr.cpp
       
    15 // Part of       : Dialogs
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "CSigCompMgr.h"
       
    22 #include "MSigComp.h"
       
    23 #include "uricontainer.h"
       
    24 #include "sipuri.h"
       
    25 #include "siprouteheader.h"
       
    26 #include "sipaddress.h"
       
    27 #include "siphostport.h"
       
    28 #include "sipstrings.h"
       
    29 #include "sipstrconsts.h"
       
    30 
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CSigCompMgr::NewL
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CSigCompMgr* CSigCompMgr::NewL (TUint32 aIapId, MSigComp& aSigComp)
       
    37 	{
       
    38 	CSigCompMgr* self = CSigCompMgr::NewLC (aIapId, aSigComp);
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CSigCompMgr::NewLC
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CSigCompMgr* CSigCompMgr::NewLC (TUint32 aIapId, MSigComp& aSigComp)
       
    48 	{
       
    49 	CSigCompMgr* self = new(ELeave)CSigCompMgr(aIapId, aSigComp);
       
    50 	CleanupStack::PushL(self);
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CSigCompMgr::CSigCompMgr
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CSigCompMgr::CSigCompMgr(TUint32 aIapId, MSigComp& aSigComp)
       
    59  : iIapId (aIapId),
       
    60    iSigComp (aSigComp)
       
    61 	{
       
    62     iCompParamName = SIPStrings::StringF(SipStrConsts::EComp);
       
    63     iSigCompValue = SIPStrings::StringF(SipStrConsts::ESigComp);
       
    64 	}
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSigCompMgr::~CSigCompMgr
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CSigCompMgr::~CSigCompMgr()
       
    71 	{
       
    72     if (iCompartmentId)
       
    73         {
       
    74         iSigComp.RemoveCompartment(iCompartmentId);
       
    75         }
       
    76 	}
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CSigCompMgr::UpdateL
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CSigCompMgr::UpdateL (const CURIContainer& aRemoteTarget,
       
    83                            const RPointerArray<CSIPRouteHeader>& aRouteSet,
       
    84                            CSIPURI& aLocalTarget,
       
    85 						   TBool aUpdateLocalTarget)
       
    86     {
       
    87 	// Update the compartment usage
       
    88     if (aRouteSet.Count() > 0 && aRouteSet[0] != 0)
       
    89         {
       
    90         const CSIPAddress& routeAddr = aRouteSet[0]->SIPAddress();
       
    91         if (routeAddr.URI().IsSIPURI())
       
    92             {
       
    93             UpdateL(*(routeAddr.URI().SIPURI()));           
       
    94             }
       
    95         }
       
    96     else 
       
    97         {
       
    98         if (aRemoteTarget.IsSIPURI())
       
    99             {
       
   100             UpdateL(*aRemoteTarget.SIPURI());
       
   101             }
       
   102         }
       
   103 	// Update local target
       
   104 	if (aUpdateLocalTarget)
       
   105 		{
       
   106 		if (iCompartmentId && !HasSigCompParameter(aLocalTarget)) 
       
   107 			{
       
   108 			// SigComp used: Add comp=sigcomp to local target
       
   109 			aLocalTarget.SetParamL(iCompParamName,iSigCompValue);
       
   110 			}
       
   111 		else
       
   112 			{
       
   113 			aLocalTarget.DeleteParam(iCompParamName);
       
   114 			}
       
   115 		}
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CSigCompMgr::CompartmentId
       
   120 // -----------------------------------------------------------------------------
       
   121 //    
       
   122 TUint32 CSigCompMgr::CompartmentId() const
       
   123     {
       
   124     return iCompartmentId;
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CSigCompMgr::HasSigCompParameter
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TBool CSigCompMgr::HasSigCompParameter (const CSIPURI& aURI) const
       
   132     {
       
   133     return (aURI.ParamValue(iCompParamName) == iSigCompValue);
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CSigCompMgr::UpdateL
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CSigCompMgr::UpdateL (const CSIPURI& aURI)
       
   141     {
       
   142     if (HasSigCompParameter(aURI))
       
   143         {
       
   144         if (!iSigComp.IsSupported())
       
   145             {
       
   146             User::Leave(KErrNotSupported);
       
   147             }
       
   148     	if (!iCompartmentId)
       
   149         	{
       
   150         	iCompartmentId = iSigComp.CreateCompartmentL(iIapId);
       
   151         	}
       
   152         }
       
   153     else
       
   154         {
       
   155         if (iCompartmentId)
       
   156             {
       
   157             iSigComp.RemoveCompartment(iCompartmentId);
       
   158             iCompartmentId = 0;
       
   159             }
       
   160         }
       
   161     }