realtimenetprots/sipfw/SIP/TransactionUser/src/RouteSet.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          : RouteSet.cpp
       
    15 // Part of       : TransactionUser
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "uricontainer.h"
       
    22 #include "sipuri.h"
       
    23 #include "sipaddress.h"
       
    24 #include "siprouteheader.h"
       
    25 #include "siprequest.h"
       
    26 #include "sipstrings.h"
       
    27 #include "sipstrconsts.h"
       
    28 #include "MSipRegistrations.h"
       
    29 
       
    30 #include "RouteSet.h"
       
    31 
       
    32 #ifdef CPPUNIT_TEST
       
    33 #include "TestCleanupStack.h"
       
    34 #endif
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CRouteSet::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CRouteSet* CRouteSet::NewL(CSIPRequest& aReq,
       
    42 						   MSipRegistrations& aRegistrations,
       
    43 						   TRegistrationId aRegisterId)
       
    44 	{
       
    45 	CRouteSet* self = new (ELeave) CRouteSet();
       
    46 	CleanupStack::PushL(self);
       
    47 	self->ConstructL(aReq, aRegistrations, aRegisterId);
       
    48 	CleanupStack::Pop(self);
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CRouteSet::NewL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CRouteSet* CRouteSet::NewL(const CRouteSet& aRouteSet)
       
    57 	{
       
    58 	CRouteSet* self = new (ELeave) CRouteSet();
       
    59 	CleanupStack::PushL(self);	
       
    60 	self->ConstructL(aRouteSet);
       
    61 	CleanupStack::Pop(self);
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CRouteSet::CRouteSet
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CRouteSet::CRouteSet()
       
    70 #ifdef CPPUNIT_TEST
       
    71     : iRoutes(1)
       
    72 #endif
       
    73 	{
       
    74 	}
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CRouteSet::ConstructL
       
    78 // If aReq contains Route-headers (=case of a pre-existing route set filled by
       
    79 // upper subsystem), they are copied to route set. Otherwise the outbound
       
    80 // proxy (if it exists) is put to the route set.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CRouteSet::ConstructL(CSIPRequest& aReq,
       
    84 						   MSipRegistrations& aRegistrations,
       
    85 						   TRegistrationId aRegisterId)
       
    86 	{
       
    87 	iPreconfigRouteExists =
       
    88 		aReq.HasHeader(SIPStrings::StringF(SipStrConsts::ERouteHeader));
       
    89 	if (iPreconfigRouteExists)
       
    90 		{
       
    91 		TSglQueIter<CSIPHeaderBase> iter =
       
    92 			aReq.Headers(SIPStrings::StringF(SipStrConsts::ERouteHeader));
       
    93 
       
    94 	    for (CSIPHeaderBase* header = iter++; header; header = iter++)
       
    95 			{
       
    96 			AddRouteL(*header);
       
    97 			}
       
    98 		}
       
    99 	else
       
   100 		{
       
   101 		const CSIPRouteHeader* proxy = 
       
   102 		    aRegistrations.OutboundProxy(aRegisterId);
       
   103 		if (proxy)
       
   104 			{
       
   105 			AddRouteL(*proxy);			
       
   106 			}
       
   107 		}
       
   108 	}
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CRouteSet::ConstructL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 void CRouteSet::ConstructL(const CRouteSet& aRouteSet)
       
   115 	{
       
   116 	iPreconfigRouteExists = aRouteSet.iPreconfigRouteExists;
       
   117 
       
   118 	for (TInt i = 0; i < aRouteSet.iRoutes.Count(); ++i)
       
   119 		{
       
   120 		AddRouteL(*aRouteSet.iRoutes[i]);
       
   121 		}
       
   122 	}
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CRouteSet::~CRouteSet
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CRouteSet::~CRouteSet()
       
   129 	{
       
   130 	iRoutes.ResetAndDestroy();
       
   131 	}
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CRouteSet::AddRouteL
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CRouteSet::AddRouteL(const CSIPHeaderBase& aRouteHeader)
       
   138 	{
       
   139     CSIPRouteHeader* route =
       
   140 		static_cast<CSIPRouteHeader*>(aRouteHeader.CloneL());
       
   141 	CleanupStack::PushL(route);
       
   142 	iRoutes.AppendL(route);
       
   143 	CleanupStack::Pop(route);
       
   144 	}
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CRouteSet::CopyToRequestL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CRouteSet::CopyToRequestL(CSIPRequest& aReq, TUint aIndex) const
       
   151 	{
       
   152 	for (TInt i = aIndex; i < iRoutes.Count(); ++i)
       
   153 		{		
       
   154 		aReq.AddHeaderL(*iRoutes[i]);
       
   155 		}
       
   156 	}
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CRouteSet::IsLrParamInTopRoute
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TBool CRouteSet::IsLrParamInTopRoute() const
       
   163 	{
       
   164 	if (IsEmpty())
       
   165 		{
       
   166 		return EFalse;
       
   167 		}
       
   168 	
       
   169 	CURIContainer& uri = iRoutes[0]->SIPAddress().URI();
       
   170 	
       
   171     return (uri.IsSIPURI() &&
       
   172     		uri.SIPURI()->HasParam(SIPStrings::StringF(SipStrConsts::ELr)));
       
   173 	}
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CRouteSet::IsEmpty
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TBool CRouteSet::IsEmpty() const
       
   180 	{
       
   181 	return iRoutes.Count() == 0;
       
   182 	}
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CRouteSet::PreconfigRouteExists
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 TBool CRouteSet::PreconfigRouteExists() const
       
   189 	{
       
   190 	return iPreconfigRouteExists;
       
   191 	}
       
   192 	
       
   193 // -----------------------------------------------------------------------------
       
   194 // CRouteSet::NextHop
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 CURIContainer& CRouteSet::NextHop(CURIContainer& aRemoteTarget) const
       
   198     {
       
   199     if (IsEmpty())
       
   200     	{
       
   201     	return aRemoteTarget;
       
   202     	}
       
   203 
       
   204     return iRoutes[0]->SIPAddress().URI();
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // CRouteSet::TopRoute
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 const CURIContainer* CRouteSet::TopUri() const
       
   212 	{
       
   213 	if (IsEmpty())
       
   214 		{
       
   215 		return NULL;
       
   216 		}
       
   217 
       
   218     return &iRoutes[0]->SIPAddress().URI();
       
   219 	}
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CRouteSet::AddToBeginningL
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CRouteSet::AddToBeginningL(const CSIPRouteHeader& aRoute,
       
   226 								TBool aOverwrite)
       
   227 	{
       
   228 	CSIPRouteHeader* route = static_cast<CSIPRouteHeader*>(aRoute.CloneL());
       
   229 	CleanupStack::PushL(route);
       
   230 
       
   231 	if (aOverwrite && !IsEmpty())
       
   232 		{
       
   233 		CSIPRouteHeader* old = iRoutes[0];
       
   234 		iRoutes.Remove(0);
       
   235 		delete old;
       
   236 		}
       
   237 
       
   238 	iRoutes.InsertL(route, 0);
       
   239 	CleanupStack::Pop(route);
       
   240 	}
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CRouteSet::IsInSet
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 TBool CRouteSet::IsInSet(const CURIContainer& aUri) const
       
   247 	{
       
   248 	for (TInt i = 0; i < iRoutes.Count(); ++i)
       
   249 		{
       
   250 		if (aUri == iRoutes[0]->SIPAddress().URI())
       
   251 			{
       
   252 			return ETrue;
       
   253 			}
       
   254 		}
       
   255 
       
   256 	return EFalse;
       
   257 	}