sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include <authority8.h>
sl@0: #include <authority16.h>
sl@0: #include "CAuthorityInternal.h"
sl@0: #include <uriutilscommon.h>
sl@0: #include <escapeutils.h>
sl@0: #include <uriutils.h>
sl@0: 
sl@0: 
sl@0: //
sl@0: //
sl@0: // Implementation of CAuthority8
sl@0: //
sl@0: //
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves nothing on the 
sl@0: 	CleanupStack. Creates an authority object which is a copy of the input parameter 
sl@0: 	aAuthority.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aAuthority	A reference to a parsed authority object.
sl@0: 	@return			A pointer to the newly created CAuthority8 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority8 object.
sl@0: */
sl@0: EXPORT_C CAuthority8* CAuthority8::NewL(const TAuthorityC8& aAuthority)
sl@0: 	{
sl@0: 	CAuthority8* self = CAuthority8::NewLC(aAuthority);
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves a pointer to created 
sl@0: 	object on the CleanupStack. Creates an authority object which is a copy of the input 
sl@0: 	parameter aAuthority.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aAuthority	A reference to a parsed authority object.
sl@0: 	@return			A pointer to the newly created CAuthority8 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority8 object.
sl@0:  */
sl@0: EXPORT_C CAuthority8* CAuthority8::NewLC(const TAuthorityC8& aAuthority)
sl@0: 	{
sl@0: 	CAuthority8* self = new (ELeave) CAuthority8(aAuthority);
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack. 
sl@0: 	Creates an authority object which is empty.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@return			A pointer to the newly created CAuthority8 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority8 object.
sl@0:  */
sl@0: EXPORT_C CAuthority8* CAuthority8::NewL()
sl@0: 	{
sl@0: 	CAuthority8* self = CAuthority8::NewLC();
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves a pointer to created object on 
sl@0: 	the CleanupStack. Creates an authority object which is empty.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@return			A pointer to the newly created CAuthority8 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority8 object.
sl@0:  */
sl@0: EXPORT_C CAuthority8* CAuthority8::NewLC()
sl@0: 	{
sl@0: 	CAuthority8* self = new (ELeave) CAuthority8(TAuthorityC8());
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Destructor.
sl@0: 	
sl@0: 	@since			6.0
sl@0:  */
sl@0: EXPORT_C CAuthority8::~CAuthority8()
sl@0: 	{
sl@0: 	delete iAuthorityBuf;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Provides a reference to the parsed authority. Allows access to the non-modifying API for TAuthorityC8.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@return			A const reference to the parsed authority object.
sl@0:  */
sl@0: EXPORT_C const TAuthorityC8& CAuthority8::Authority() const
sl@0: 	{
sl@0: 	return iAuthority;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Sets the specified component in the authority. The component is set to the value given in the argument 
sl@0: 	aData. If the specified component already exists then it is replaced with the new value.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aData		A descriptor pointer to the new value for the authority component.
sl@0: 	@param			aComponent	An enum specifying the component to be set.
sl@0: 	@pre 			Object is fully constructed.
sl@0: 	@post			The authority has the specified component set to the new value.
sl@0: 	@Leave          KErrArgument  If aComponent goes out of range.
sl@0:  */
sl@0: EXPORT_C void CAuthority8::SetComponentL(const TDesC8& aData, TAuthorityComponent aComponent)
sl@0: 	{		
sl@0: 	// Update the appropriate component table entry
sl@0: 	iAuthority.iComponent[aComponent].Set(aData);
sl@0: 
sl@0: 	// Copy to the buffer by forming the Authority
sl@0: 	FormAuthorityL();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Escape encodes the component then sets the specified component in the authority. The component is set to the 
sl@0: 	value given in the argument aData. If the specified component already exists then it is replaced with the new 
sl@0: 	value.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aData		A descriptor pointer to the new value for the authority component.
sl@0: 	@param			aComponent	An enum specifying the component to be set.
sl@0: 	@pre 			Object is fully constructed.
sl@0: 	@post			The authority has the specified component set to the new value.
sl@0:  */
sl@0: EXPORT_C void CAuthority8::SetAndEscapeComponentL(const TDesC8& aData, TAuthorityComponent aComponent)
sl@0: 	{
sl@0: 	// Create escaped version of component
sl@0: 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aData, EscapeUtils::EEscapeAuth);
sl@0: 	CleanupStack::PushL(escaped);
sl@0: 
sl@0: 	// Set the component	
sl@0: 	if(aComponent<EAuthorityMaxComponents && aComponent >=EAuthorityUserinfo )
sl@0: 	   {
sl@0: 	    SetComponentL(*escaped, aComponent);
sl@0: 	   }
sl@0: 	else
sl@0: 	   {
sl@0: 		User::Leave(KErrArgument);	
sl@0: 	   }
sl@0: 
sl@0: 	// Cleanup
sl@0: 	CleanupStack::PopAndDestroy(escaped);
sl@0: 	}
sl@0: 	
sl@0: /**
sl@0: 	Removes the specified component from the authority. If the component does not exist then this function does 
sl@0: 	nothing.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aComponent	An enum specifying the component to be removed.
sl@0: 	@pre 			Object is fully constructed.
sl@0: 	@post			The authority is updated to exclude the specified component.
sl@0:  */
sl@0: EXPORT_C void CAuthority8::RemoveComponentL(TAuthorityComponent aComponent)
sl@0: 	{
sl@0: 	if( iAuthority.IsPresent(aComponent) )
sl@0: 		{
sl@0: 		// Remove the component - set pointer to NULL and length to zero
sl@0: 		iAuthority.iComponent[aComponent].Set(NULL,0);
sl@0: 
sl@0: 		// Re-form buffer and component table
sl@0: 		FormAuthorityL();
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Constructor. First phase of two-phase construction method. Does non-allocating construction.
sl@0: 	
sl@0: 	@param			aNewAuthority	The parsed authority component information from which 
sl@0: 	to create the authority.
sl@0: 	@since			6.0
sl@0:  */
sl@0: CAuthority8::CAuthority8(const TAuthorityC8& aNewAuthority)
sl@0: : CBase(), iAuthority(aNewAuthority)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Second phase of two-phase construction method. Does any allocations required to fully construct 
sl@0: 	the object.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@pre 			First phase of construction is complete.
sl@0: 	@post			The object is fully constructed and initialized.
sl@0:  */
sl@0: void CAuthority8::ConstructL()
sl@0: 	{
sl@0: 	// Create the HBufC8
sl@0: 	FormAuthorityL();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Forms the authority from the parsed authority information. A copy of the parsed authority is created. 
sl@0: 	The parsed authority is changed to refer to the copy.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@pre 			The parsed authority information is set.
sl@0: 	@post			The authority buffer is a copy of the parsed authority, and the 
sl@0: 	parsed authority now refers to the copy.
sl@0:  */
sl@0: void CAuthority8::FormAuthorityL()
sl@0: 	{
sl@0: 	TBool isIPv6Host;
sl@0: 
sl@0: 	// Calculate length of of the Authority
sl@0: 	TInt length = CalculateAuthorityLength(iAuthority.iComponent, isIPv6Host);
sl@0: 
sl@0: 	// Create a temporary buffer and descriptor pointer to it
sl@0: 	HBufC8* buf = HBufC8::NewL(length);
sl@0: 	TPtr8 authority = buf->Des();
sl@0: 
sl@0: 	// Create the authority, updating the internal authority object
sl@0: 	DoFormAuthority(authority, iAuthority.iComponent, isIPv6Host);
sl@0: 
sl@0: 	// Update the internal buffer and descriptor pointer for the authority object
sl@0: 	delete iAuthorityBuf;
sl@0: 	iAuthorityBuf = buf;
sl@0: 	iAuthority.iAuthorityDes.Set(iAuthorityBuf->Des());
sl@0: 	}
sl@0: 
sl@0: //
sl@0: //
sl@0: // Implementation of CAuthority16
sl@0: //
sl@0: //
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack. 
sl@0: 	Creates an authority object which is a copy of the input parameter aAuthority.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@param			aAuthority	A reference to a parsed authority object.
sl@0: 	@return			A pointer to the newly created CAuthority16 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority16 object.
sl@0:  */
sl@0: EXPORT_C CAuthority16* CAuthority16::NewL(const TAuthorityC16& aAuthority)
sl@0: 	{
sl@0: 	CAuthority16* self = CAuthority16::NewLC(aAuthority);
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves a pointer to created object on 
sl@0: 	the CleanupStack. Creates an authority object which is a copy of the input parameter aAuthority.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@param			aAuthority	A reference to a parsed authority object.
sl@0: 	@return			A pointer to the newly created CAuthority16 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority16 object.
sl@0:  */
sl@0: EXPORT_C CAuthority16* CAuthority16::NewLC(const TAuthorityC16& aAuthority)
sl@0: 	{
sl@0: 	CAuthority16* self = new (ELeave) CAuthority16(aAuthority);
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack. 
sl@0: 	Creates an authority object which is empty.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@return			A pointer to the newly created CAuthority16 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority16 object.
sl@0:  */
sl@0: EXPORT_C CAuthority16* CAuthority16::NewL()
sl@0: 	{
sl@0: 	CAuthority16* self = CAuthority16::NewLC();
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Static factory constructor. Uses two phase construction and leaves a pointer to created object on the 
sl@0: 	CleanupStack. Creates an authority object which is empty.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@return			A pointer to the newly created CAuthority16 object. 
sl@0: 	@post			A fully constructed and initialized CAuthority16 object.
sl@0:  */
sl@0: EXPORT_C CAuthority16* CAuthority16::NewLC()
sl@0: 	{
sl@0: 	CAuthority16* self = new (ELeave) CAuthority16(TAuthorityC16());
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Destructor.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0:  */
sl@0: EXPORT_C CAuthority16::~CAuthority16()
sl@0: 	{
sl@0: 	delete iAuthorityBuf;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Provides a reference to the parsed authority. Allows access to the non-modifying API for TAuthorityC.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@return			A const reference to the parsed authority object.
sl@0:  */
sl@0: EXPORT_C const TAuthorityC16& CAuthority16::Authority() const
sl@0: 	{
sl@0: 	return iAuthority;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Sets the specified component in the authority. The component is set to the value given in the argument aData. 
sl@0: 	If the specified component already exists then it is replaced with the new value.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@param			aData		A descriptor pointer to the new value for the authority component.
sl@0: 	@param			aComponent	An enum specifying the component to be set.
sl@0: 	@pre 			Object is fully constructed.
sl@0: 	@post			The authority has the specified component set to the new value.
sl@0: 	@Leave          KErrArgument  If aComponent goes out of range.
sl@0:  */
sl@0: EXPORT_C void CAuthority16::SetComponentL(const TDesC16& aData, TAuthorityComponent aComponent)
sl@0: 	{
sl@0: 	// Update the appropriate component table entry
sl@0: 	iAuthority.iComponent[aComponent].Set(aData);
sl@0: 
sl@0: 	// Copy to the buffer by forming the Authority
sl@0: 	FormAuthorityL();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Escape encodes the component then sets the specified component in the authority. The component is set to the 
sl@0: 	value given in the argument aData. If the specified component already exists then it is replaced with the new 
sl@0: 	value.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@param			aData		A descriptor pointer to the new value for the authority component.
sl@0: 	@param			aComponent	An enum specifying the component to be set.
sl@0: 	@pre 			Object is fully constructed.
sl@0: 	@post			The authority has the specified component set to the new value.
sl@0:  */
sl@0: EXPORT_C void CAuthority16::SetAndEscapeComponentL(const TDesC16& aData, TAuthorityComponent aComponent)
sl@0: 	{
sl@0: 	// Need to convert to utf8 first
sl@0: 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aData);
sl@0: 	CleanupStack::PushL(utf8);
sl@0: 
sl@0: 	// Create escaped version of component
sl@0: 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapeAuth);
sl@0: 	CleanupStack::PushL(escaped);
sl@0: 
sl@0: 	// Convert back to 16-bits
sl@0: 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
sl@0: 	converted->Des().Copy(*escaped);
sl@0: 
sl@0: 	// Set the component
sl@0: 	if(aComponent<EAuthorityMaxComponents && aComponent >=EAuthorityUserinfo )
sl@0: 	   {
sl@0: 		SetComponentL(*converted, aComponent);
sl@0: 	   }
sl@0:     else
sl@0: 	   {
sl@0: 		User::Leave(KErrArgument);	
sl@0: 	   }	
sl@0: 
sl@0: 	// Cleanup
sl@0: 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Removes the specified component from the authority. If the component does not exist then this 
sl@0: 	function does nothing.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@deprecated 	Deprecated in 9.1
sl@0: 	@param			aComponent	An enum specifying the component to be removed.
sl@0: 	@pre 			Object is fully constructed.
sl@0: 	@post			The authority is updated to exclude the specified component.
sl@0:  */
sl@0: EXPORT_C void CAuthority16::RemoveComponentL(TAuthorityComponent aComponent)
sl@0: 	{
sl@0: 	if( iAuthority.IsPresent(aComponent) )
sl@0: 		{
sl@0: 		// Remove the component - set pointer to NULL and length to zero
sl@0: 		iAuthority.iComponent[aComponent].Set(NULL,0);
sl@0: 
sl@0: 		// Re-form buffer and component table
sl@0: 		FormAuthorityL();
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Constructor. First phase of two-phase construction method. Does non-allocating construction.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aNewAuthority	The parsed authority component information from which 
sl@0: 	to create the authority.
sl@0:  */
sl@0: CAuthority16::CAuthority16(const TAuthorityC16& aNewAuthority)
sl@0: : CBase(), iAuthority(aNewAuthority)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Second phase of two-phase construction method. Does any allocations required to fully construct 
sl@0: 	the object.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@pre 			First phase of construction is complete.
sl@0: 	@post			The object is fully constructed and initialized.
sl@0:  */
sl@0: void CAuthority16::ConstructL()
sl@0: 	{
sl@0: 	// Create the HBufC16
sl@0: 	FormAuthorityL();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Forms the authority from the parsed authority information. A copy of the parsed authority is created.
sl@0: 	The parsed authority is changed to refer to the copy.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@pre 			The parsed authority information is set.
sl@0: 	@post			The authority buffer is a copy of the parsed authority, and the 
sl@0: 					parsed authority now refers to the copy.
sl@0:  */
sl@0: void CAuthority16::FormAuthorityL()
sl@0: 	{
sl@0: 	TBool isIPv6Host;
sl@0: 
sl@0: 	// Calculate length of of the Authority
sl@0: 	TInt length = CalculateAuthorityLength(iAuthority.iComponent, isIPv6Host);
sl@0: 
sl@0: 	// Create a temporary buffer and descriptor pointer to it
sl@0: 	HBufC16* buf = HBufC16::NewL(length);
sl@0: 	TPtr16 authority = buf->Des();
sl@0: 
sl@0: 	// Create the authority, updating the internal authority object
sl@0: 	DoFormAuthority(authority, iAuthority.iComponent, isIPv6Host);
sl@0: 
sl@0: 	// Update the internal buffer and descriptor pointer for the authority object
sl@0: 	delete iAuthorityBuf;
sl@0: 	iAuthorityBuf = buf;
sl@0: 	iAuthority.iAuthorityDes.Set(iAuthorityBuf->Des());
sl@0: 	}
sl@0: 
sl@0: //
sl@0: //
sl@0: // Implementation of templated LOCAL functions
sl@0: //
sl@0: //
sl@0: 
sl@0: /**
sl@0: 	Calculates the length of the authority from a list of the components.
sl@0: 					  
sl@0: 	@since			6.0
sl@0: 	@param			aComponent	The array of descriptor pointers to the authority 
sl@0: 	components.
sl@0: 	@param			aIsIPv6Host	Specifies ETrue or EFalse.
sl@0: 	@return			The length of the authority including the required delimiters.	
sl@0: */
sl@0: template<class TPtrCType>
sl@0: TInt CalculateAuthorityLength(const TPtrCType aComponent[], TBool& aIsIPv6Host)
sl@0: 	{
sl@0: 	aIsIPv6Host = EFalse;
sl@0: 	TInt length=0;
sl@0: 	for( TInt i=0; i<EAuthorityMaxComponents; ++i )
sl@0: 		{
sl@0: 		if( aComponent[i].Ptr() )
sl@0: 			{
sl@0: 			length += aComponent[i].Length();
sl@0: 			// Need to make space for a delimiter if not a host
sl@0: 			if( i != EAuthorityHost )
sl@0: 				++length;
sl@0: 			else
sl@0: 				// Check the host type
sl@0: 				if (UriUtils::HostType(aComponent[i]) == UriUtils::EIPv6Host)
sl@0: 					{
sl@0: 					// If its an IPv6 format host, need to increase the length for the []
sl@0: 					aIsIPv6Host = ETrue;
sl@0: 					length+=2;
sl@0: 					}
sl@0: 			}
sl@0: 		}
sl@0: 	return length;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Templated function to form an authority. The new authority component information is given by 
sl@0: 	the input/output argument aComponent. For each authority component that exists in aComponent, 
sl@0: 	that component and its appropriate delimiters are appended to aAuthority. Then the components 
sl@0: 	in aComponent are updated to refer to the copied versions in aUri.
sl@0: 	
sl@0: 	@since			6.0
sl@0: 	@param			aAuthority	The descriptor pointer to buffer to be appended.
sl@0: 	@param			aComponent	The array of descriptor pointers to be copied and 
sl@0: 	then updated.
sl@0: 	@param			aIsIPv6Host	Specifies ETrue or EFalse.
sl@0: 	@pre 			The buffer pointed to by aAuthority should be large enough 
sl@0: 	to have the authority components given in aNewComponent copied into it, as well as 
sl@0: 	the required delimiters.
sl@0: 	@post			The authority buffer will have a copy of the authority defined in
sl@0: 	aNewComponent, and aOldComponent will refer to copies of these components in aAuthority.
sl@0: */
sl@0: template<class TPtrType, class TPtrCType>
sl@0: void DoFormAuthority(TPtrType& aAuthority, TPtrCType aComponent[], const TBool& aIsIPv6Host)
sl@0: 	{
sl@0: 	if( aComponent[EAuthorityUserinfo].Ptr() )
sl@0: 		{
sl@0: 		// Update the userinfo
sl@0: 		SetUserinfo(aAuthority, aComponent[EAuthorityUserinfo]);
sl@0: 		}
sl@0: 	if( aComponent[EAuthorityHost].Ptr() )
sl@0: 		{
sl@0: 		// Update the host
sl@0: 		SetHost(aAuthority, aComponent[EAuthorityHost], aIsIPv6Host);
sl@0: 		}
sl@0: 	if( aComponent[EAuthorityPort].Ptr() )
sl@0: 		{
sl@0: 		// Update the port
sl@0: 		SetPort(aAuthority, aComponent[EAuthorityPort]);
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Templated function to set the userinfo in an authority. The output argument aAuthority points to 
sl@0: 	the descriptor buffer into which aNewUserInfo will be copied. The argument aOldUserInfo is updated 
sl@0: 	to point to the copied version of aNewUserInfo in aAuthority.
sl@0: 						
sl@0: 	@warning		This function will panic with KAuthorityErrBufferOverflow if there is not
sl@0: 	enough space in the descriptor to append the component and any required delimiters.
sl@0: 	@since			6.0
sl@0: 	@param			aAuthority	The descriptor pointer to buffer to be appended.
sl@0: 	@param			aUserinfo	The descriptor pointer to the userinfo component to be copied 
sl@0: 	and then updated.
sl@0: 	@pre 			The buffer pointed to by aAuthority should be large enough to have 
sl@0: 	aNewUserInfo appended to it with the required delimiter.
sl@0: 	@post			The authority buffer now includes aNewUserInfo and aOldUserInfo points
sl@0: 	to the copy of the userinfo component in aAuthority.
sl@0: */
sl@0: template<class TPtrType, class TPtrCType> 
sl@0: void SetUserinfo(TPtrType& aAuthority, TPtrCType& aUserinfo)
sl@0: 	{
sl@0: 	// Append the userinfo and delimiter
sl@0: 	aAuthority.Append(aUserinfo);
sl@0: 	aAuthority.Append(KUserinfoDelimiter);
sl@0: 
sl@0: 	// Update the component table
sl@0: 	aUserinfo.Set(aAuthority.Left(aUserinfo.Length()));
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Templated function to set the host in an authority. The output argument aAuthority points to the 
sl@0: 	descriptor buffer into which aNewHost will be copied. The argument aOldHost is updated to point to 
sl@0: 	the copied version of aNewHost in aAuthority.
sl@0: 						
sl@0: 	@warning		This function will panic with KAuthorityErrBufferOverflow if there is not
sl@0: 	enough space in the descriptor to append the component and any required delimiters.
sl@0: 	@since			6.0
sl@0: 	@param			aAuthority	The descriptor pointer to buffer to appended.
sl@0: 	@param			aHost		The descriptor pointer to the host component to be copied 
sl@0: 	and then updated.
sl@0: 	@param			aIsIPv6Host	Specifies ETrue or EFalse.
sl@0: 	@pre 			The buffer pointed to by aAuthority should be large enough to have 
sl@0: 	aNewHost appended to it with the required delimiter.
sl@0: 	@post			The authority buffer now includes aNewHost and aOldHost points to the 
sl@0: 	copy of the host component in aAuthority.
sl@0: */
sl@0: template<class TPtrType, class TPtrCType> 
sl@0: void SetHost(TPtrType& aAuthority, TPtrCType& aHost, const TBool& aIsIPv6Host)
sl@0: 	{
sl@0: 	if (aIsIPv6Host)
sl@0: 		{
sl@0: 		aAuthority.Append(KIPv6UriOpenBrace);
sl@0: 		aAuthority.Append(aHost);
sl@0: 		aAuthority.Append(KIPv6UriCloseBrace);
sl@0: 
sl@0: 		// Position = (length of uri - length of host) - length of end brace
sl@0: 		aHost.Set( aAuthority.Mid((aAuthority.Length()-aHost.Length())-1, aHost.Length()) );
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		// Append the host
sl@0: 		aAuthority.Append(aHost);
sl@0: 
sl@0: 		// Update the component table
sl@0: 		aHost.Set(aAuthority.Right(aHost.Length()));
sl@0: 		}
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: 	Templated function to set the port in an authority. The output argument aAuthority points to the 
sl@0: 	descriptor buffer into which aNewPort will be copied. The argument aOldPort is updated to point to 
sl@0: 	the copied version of aNewPort in aAuthority.
sl@0: 						
sl@0: 	@warning		This function will panic with KAuthorityErrBufferOverflow if there is not
sl@0: 	enough space in the descriptor to append the component and any required delimiters.
sl@0: 	@since			6.0
sl@0: 	@param			aAuthority	The descriptor pointer to buffer to appended.
sl@0: 	@param			aPort		The descriptor pointer to the port component to be copied 
sl@0: 	and then updated.
sl@0: 	@pre 			The buffer pointed to by aAuthority should be large enough to have aNewPort
sl@0: 	appended to it with the required delimiter.
sl@0: 	@post			The authority buffer now includes aNewPort and aOldPort points to the 
sl@0: 	copy of the port component in aAuthority.
sl@0: */
sl@0: template<class TPtrType, class TPtrCType> 
sl@0: void SetPort(TPtrType& aAuthority, TPtrCType& aPort)
sl@0: 	{
sl@0: 	// Append delimiter and the port
sl@0: 	aAuthority.Append(KPortDelimiter);
sl@0: 	aAuthority.Append(aPort);
sl@0: 
sl@0: 	// Update the component table
sl@0: 	aPort.Set(aAuthority.Right(aPort.Length()));
sl@0: 	}