os/ossrv/genericservices/httputils/AuthorityParser/TAuthorityC.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericservices/httputils/AuthorityParser/TAuthorityC.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,291 @@
     1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <authority8.h>
    1.20 +#include <authority16.h>
    1.21 +#include <uriutilscommon.h>
    1.22 +#include <escapeutils.h>
    1.23 +
    1.24 +// Panic category
    1.25 +//
    1.26 +_LIT(KAuthorityPanicCategory,"AUTHORITY"); 
    1.27 +
    1.28 +//
    1.29 +//
    1.30 +// Implementation of TAuthorityC8
    1.31 +//
    1.32 +//
    1.33 +
    1.34 +/**
    1.35 +	Constructor.
    1.36 +	
    1.37 +	@since			6.0
    1.38 + */
    1.39 +EXPORT_C TAuthorityC8::TAuthorityC8()
    1.40 +	{
    1.41 +	// Reset the component table and the Authority
    1.42 +	Reset();
    1.43 +	}
    1.44 +
    1.45 +/**
    1.46 +	Retrieves the specified component in the authority.
    1.47 +	
    1.48 +	@since			6.0
    1.49 +	@param			aComponent	The enum specifying the component.
    1.50 +	@return			A constant reference to a descriptor pointer to the specified component.
    1.51 + */
    1.52 +EXPORT_C const TDesC8& TAuthorityC8::Extract(TAuthorityComponent aComponent) const
    1.53 +	{
    1.54 +	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
    1.55 +
    1.56 +	return iComponent[aComponent];
    1.57 +	}
    1.58 +
    1.59 +/**
    1.60 +	Indicates whether the specified component is present in the authority.
    1.61 +	
    1.62 +	@since			6.0
    1.63 +	@param			aComponent	The enum specifying the component.
    1.64 +	@return			A boolean value of ETrue if the desired component is present, 
    1.65 +	or EFalse if the desired component is not present.
    1.66 + */
    1.67 +EXPORT_C TBool TAuthorityC8::IsPresent(TAuthorityComponent aComponent) const
    1.68 +	{
    1.69 +	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
    1.70 +
    1.71 +	TBool present = TBool(iComponent[aComponent].Ptr());
    1.72 +	return present;
    1.73 +	}
    1.74 +
    1.75 +/**
    1.76 +	Compares the specified component against the one in the authority passed in.
    1.77 +	
    1.78 +	@since			6.0
    1.79 +	@param			aAuthority	The authority to compare components against.
    1.80 +	@param			aComponent	The enum specifying the component to compare.
    1.81 +	@return			An integer value of zero if the components are the same, any other
    1.82 +	value if the components are not the same.
    1.83 + */
    1.84 +EXPORT_C TInt TAuthorityC8::Compare(const TAuthorityC8& aAuthority, TAuthorityComponent aComponent) const
    1.85 +	{
    1.86 +	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
    1.87 +
    1.88 +	// Does the component exist in both the Authoritys
    1.89 +	if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
    1.90 +		{
    1.91 +		if( aComponent == EAuthorityHost )
    1.92 +			{
    1.93 +			// Do case insensitive compare for host
    1.94 +			return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
    1.95 +			}
    1.96 +		else
    1.97 +			{
    1.98 +			// Do case sensitive compare for all other components
    1.99 +			return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
   1.100 +			}
   1.101 +		}
   1.102 +	else
   1.103 +		return KErrNotFound;
   1.104 +	}
   1.105 +
   1.106 +/**
   1.107 +	Retrieves the descriptor for the entire authority.
   1.108 +	
   1.109 +	@since			6.0
   1.110 +	@return			A const reference to a descriptor pointer to the authority.
   1.111 + */
   1.112 +EXPORT_C const TDesC8& TAuthorityC8::AuthorityDes() const
   1.113 +	{
   1.114 +	return iAuthorityDes;
   1.115 +	}
   1.116 +
   1.117 +/** 
   1.118 +	Create a new HBufC descriptor containing the desired component or the full Authority.
   1.119 +	
   1.120 +	@param	aComponent  The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment)
   1.121 +	or the full authority (EAuthorityComplete -- the default)).
   1.122 +	@return the descriptor containing the desired component. 
   1.123 + */
   1.124 +EXPORT_C HBufC* TAuthorityC8::DisplayFormL(TAuthorityComponent aComponent ) const
   1.125 +	{
   1.126 +	TPtrC8 component;
   1.127 +	
   1.128 +	if ( aComponent == EAuthorityComplete) // extract the full authority
   1.129 +		{
   1.130 +		component.Set(iAuthorityDes);
   1.131 +		}
   1.132 +	else
   1.133 +		{ // extract the specified component, will Panic if invalid
   1.134 +		component.Set( Extract(aComponent) );
   1.135 +		}
   1.136 +	// convert descriptor from UTF-8 into Unicode
   1.137 +	return EscapeUtils::ConvertToUnicodeFromUtf8L(component);
   1.138 +	}
   1.139 +
   1.140 +
   1.141 +/**
   1.142 +	@internalComponent
   1.143 +	Resets the descriptor pointers for the authority components and the authority.
   1.144 +	
   1.145 +	@since			6.0
   1.146 +	@post			All authority component information is removed and the authority 
   1.147 +	descriptor is set to NULL.
   1.148 + */
   1.149 +void TAuthorityC8::Reset()
   1.150 +	{
   1.151 +	// Set descriptor pointers to NULL and lengths to zero
   1.152 +	for( TInt i=0; i<EAuthorityMaxComponents; ++i )
   1.153 +		{
   1.154 +		iComponent[i].Set(NULL,0);
   1.155 +		}
   1.156 +	iAuthorityDes.Set(NULL,0);
   1.157 +	}
   1.158 +
   1.159 +//
   1.160 +//
   1.161 +// Implementation of TAuthorityC16
   1.162 +//
   1.163 +//
   1.164 +
   1.165 +/**
   1.166 +	Constructor.
   1.167 +	
   1.168 +	@since			6.0
   1.169 +	@deprecated Deprecated in 9.1
   1.170 +*/
   1.171 +EXPORT_C TAuthorityC16::TAuthorityC16()
   1.172 +	{
   1.173 +	// Reset the component table and the Authority
   1.174 +	Reset();
   1.175 +	}
   1.176 +
   1.177 +/**
   1.178 +	Retrieves the specified component in the authority.
   1.179 +	
   1.180 +	@since			6.0
   1.181 +	@deprecated Deprecated in 9.1
   1.182 +	@param			aComponent	The enum specifying the component.
   1.183 +	@return			A constant reference to a descriptor pointer to the specified component.
   1.184 + */
   1.185 +EXPORT_C const TDesC16& TAuthorityC16::Extract(TAuthorityComponent aComponent) const
   1.186 +	{
   1.187 +	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
   1.188 +
   1.189 +	return iComponent[aComponent];
   1.190 +	}
   1.191 +
   1.192 +/**
   1.193 +	Indicates whether the specified component is present in the authority.
   1.194 +	
   1.195 +	@since			6.0
   1.196 +	@deprecated Deprecated in 9.1
   1.197 +	@param			aComponent	The enum specifying the component.
   1.198 +	@return			A boolean value of ETrue if the desired component is present, 
   1.199 +	or EFalse if the desired component is not present.
   1.200 + */
   1.201 +EXPORT_C TBool TAuthorityC16::IsPresent(TAuthorityComponent aComponent) const
   1.202 +	{
   1.203 +	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
   1.204 +
   1.205 +	TBool present = iComponent[aComponent].Ptr() ? ETrue : EFalse;
   1.206 +	return present;
   1.207 +	}
   1.208 +
   1.209 +/**
   1.210 +	Compares the specified component against the one in the authority passed in.
   1.211 +	
   1.212 +	@since			6.0
   1.213 +	@deprecated Deprecated in 9.1
   1.214 +	@param			aAuthority	The authority to compare components against.
   1.215 +	@param			aComponent	The enum specifying the component to compare.
   1.216 +	@return			An integer value of zero if the components are the same, any other
   1.217 +	value if the components are not the same.
   1.218 + */
   1.219 +EXPORT_C TInt TAuthorityC16::Compare(const TAuthorityC16& aAuthority, TAuthorityComponent aComponent) const
   1.220 +	{
   1.221 +	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
   1.222 +
   1.223 +	// Does the component exist in both the Authoritys
   1.224 +	if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
   1.225 +		{
   1.226 +		if( aComponent == EAuthorityHost )
   1.227 +			{
   1.228 +			// Do case insensitive compare for host
   1.229 +			return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
   1.230 +			}
   1.231 +		else
   1.232 +			{
   1.233 +			// Do case sensitive compare for all other components
   1.234 +			return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
   1.235 +			}
   1.236 +		}
   1.237 +	else
   1.238 +		return KErrNotFound;
   1.239 +	}
   1.240 +
   1.241 +/**
   1.242 +	Retrieves the descriptor for the entire authority.
   1.243 +	
   1.244 +	@since			6.0
   1.245 +	@deprecated Deprecated in 9.1
   1.246 +	@return			A const reference to a descriptor pointer to the authority.
   1.247 + */
   1.248 +EXPORT_C const TDesC16& TAuthorityC16::AuthorityDes() const
   1.249 +	{
   1.250 +	return iAuthorityDes;
   1.251 +	}
   1.252 +	
   1.253 +/** 
   1.254 +	Create a new HBufC descriptor containing the desired component or the full authority.
   1.255 +	
   1.256 +	@param   aComponent   The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment), 
   1.257 +				the full authority (EAuthorityComplete -- the default), or the final segment of the path (EAuthorityTail).
   1.258 +	@return     the descriptor containing the desired component. 
   1.259 +	@deprecated     Deprecated in 9.1. Provided for compatibility.
   1.260 + */
   1.261 +EXPORT_C HBufC* TAuthorityC16::DisplayFormL(TAuthorityComponent aComponent) const
   1.262 +	{
   1.263 +	TPtrC component;
   1.264 +	if ( aComponent == EAuthorityComplete) // extract the full authority
   1.265 +		{
   1.266 +		component.Set(iAuthorityDes);
   1.267 +		}
   1.268 +	else
   1.269 +		{ // extract the specified component, will Panic if invalid
   1.270 +		component.Set( Extract(aComponent) );
   1.271 +	}
   1.272 +
   1.273 +	return component.AllocL();
   1.274 +	}
   1.275 +
   1.276 +/**
   1.277 +	@internalComponent
   1.278 +	Resets the descriptor pointers for the authority components and the authority.
   1.279 +	
   1.280 +	@since			6.0
   1.281 +	@deprecated Deprecated in 9.1
   1.282 +	@post			All authority component information is removed and the authority 
   1.283 +	descriptor is set to NULL.
   1.284 + */
   1.285 +void TAuthorityC16::Reset()
   1.286 +	{
   1.287 +	// Set descriptor pointers to NULL and lengths to zero
   1.288 +	for( TInt i=0; i<EAuthorityMaxComponents; ++i )
   1.289 +		{
   1.290 +		iComponent[i].Set(NULL,0);
   1.291 +		}
   1.292 +	iAuthorityDes.Set(NULL,0);
   1.293 +	}
   1.294 +