os/ossrv/genericservices/httputils/AuthorityParser/TAuthorityC.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2001-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 //
    15 
    16 #include <authority8.h>
    17 #include <authority16.h>
    18 #include <uriutilscommon.h>
    19 #include <escapeutils.h>
    20 
    21 // Panic category
    22 //
    23 _LIT(KAuthorityPanicCategory,"AUTHORITY"); 
    24 
    25 //
    26 //
    27 // Implementation of TAuthorityC8
    28 //
    29 //
    30 
    31 /**
    32 	Constructor.
    33 	
    34 	@since			6.0
    35  */
    36 EXPORT_C TAuthorityC8::TAuthorityC8()
    37 	{
    38 	// Reset the component table and the Authority
    39 	Reset();
    40 	}
    41 
    42 /**
    43 	Retrieves the specified component in the authority.
    44 	
    45 	@since			6.0
    46 	@param			aComponent	The enum specifying the component.
    47 	@return			A constant reference to a descriptor pointer to the specified component.
    48  */
    49 EXPORT_C const TDesC8& TAuthorityC8::Extract(TAuthorityComponent aComponent) const
    50 	{
    51 	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
    52 
    53 	return iComponent[aComponent];
    54 	}
    55 
    56 /**
    57 	Indicates whether the specified component is present in the authority.
    58 	
    59 	@since			6.0
    60 	@param			aComponent	The enum specifying the component.
    61 	@return			A boolean value of ETrue if the desired component is present, 
    62 	or EFalse if the desired component is not present.
    63  */
    64 EXPORT_C TBool TAuthorityC8::IsPresent(TAuthorityComponent aComponent) const
    65 	{
    66 	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
    67 
    68 	TBool present = TBool(iComponent[aComponent].Ptr());
    69 	return present;
    70 	}
    71 
    72 /**
    73 	Compares the specified component against the one in the authority passed in.
    74 	
    75 	@since			6.0
    76 	@param			aAuthority	The authority to compare components against.
    77 	@param			aComponent	The enum specifying the component to compare.
    78 	@return			An integer value of zero if the components are the same, any other
    79 	value if the components are not the same.
    80  */
    81 EXPORT_C TInt TAuthorityC8::Compare(const TAuthorityC8& aAuthority, TAuthorityComponent aComponent) const
    82 	{
    83 	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
    84 
    85 	// Does the component exist in both the Authoritys
    86 	if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
    87 		{
    88 		if( aComponent == EAuthorityHost )
    89 			{
    90 			// Do case insensitive compare for host
    91 			return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
    92 			}
    93 		else
    94 			{
    95 			// Do case sensitive compare for all other components
    96 			return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
    97 			}
    98 		}
    99 	else
   100 		return KErrNotFound;
   101 	}
   102 
   103 /**
   104 	Retrieves the descriptor for the entire authority.
   105 	
   106 	@since			6.0
   107 	@return			A const reference to a descriptor pointer to the authority.
   108  */
   109 EXPORT_C const TDesC8& TAuthorityC8::AuthorityDes() const
   110 	{
   111 	return iAuthorityDes;
   112 	}
   113 
   114 /** 
   115 	Create a new HBufC descriptor containing the desired component or the full Authority.
   116 	
   117 	@param	aComponent  The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment)
   118 	or the full authority (EAuthorityComplete -- the default)).
   119 	@return the descriptor containing the desired component. 
   120  */
   121 EXPORT_C HBufC* TAuthorityC8::DisplayFormL(TAuthorityComponent aComponent ) const
   122 	{
   123 	TPtrC8 component;
   124 	
   125 	if ( aComponent == EAuthorityComplete) // extract the full authority
   126 		{
   127 		component.Set(iAuthorityDes);
   128 		}
   129 	else
   130 		{ // extract the specified component, will Panic if invalid
   131 		component.Set( Extract(aComponent) );
   132 		}
   133 	// convert descriptor from UTF-8 into Unicode
   134 	return EscapeUtils::ConvertToUnicodeFromUtf8L(component);
   135 	}
   136 
   137 
   138 /**
   139 	@internalComponent
   140 	Resets the descriptor pointers for the authority components and the authority.
   141 	
   142 	@since			6.0
   143 	@post			All authority component information is removed and the authority 
   144 	descriptor is set to NULL.
   145  */
   146 void TAuthorityC8::Reset()
   147 	{
   148 	// Set descriptor pointers to NULL and lengths to zero
   149 	for( TInt i=0; i<EAuthorityMaxComponents; ++i )
   150 		{
   151 		iComponent[i].Set(NULL,0);
   152 		}
   153 	iAuthorityDes.Set(NULL,0);
   154 	}
   155 
   156 //
   157 //
   158 // Implementation of TAuthorityC16
   159 //
   160 //
   161 
   162 /**
   163 	Constructor.
   164 	
   165 	@since			6.0
   166 	@deprecated Deprecated in 9.1
   167 */
   168 EXPORT_C TAuthorityC16::TAuthorityC16()
   169 	{
   170 	// Reset the component table and the Authority
   171 	Reset();
   172 	}
   173 
   174 /**
   175 	Retrieves the specified component in the authority.
   176 	
   177 	@since			6.0
   178 	@deprecated Deprecated in 9.1
   179 	@param			aComponent	The enum specifying the component.
   180 	@return			A constant reference to a descriptor pointer to the specified component.
   181  */
   182 EXPORT_C const TDesC16& TAuthorityC16::Extract(TAuthorityComponent aComponent) const
   183 	{
   184 	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
   185 
   186 	return iComponent[aComponent];
   187 	}
   188 
   189 /**
   190 	Indicates whether the specified component is present in the authority.
   191 	
   192 	@since			6.0
   193 	@deprecated Deprecated in 9.1
   194 	@param			aComponent	The enum specifying the component.
   195 	@return			A boolean value of ETrue if the desired component is present, 
   196 	or EFalse if the desired component is not present.
   197  */
   198 EXPORT_C TBool TAuthorityC16::IsPresent(TAuthorityComponent aComponent) const
   199 	{
   200 	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
   201 
   202 	TBool present = iComponent[aComponent].Ptr() ? ETrue : EFalse;
   203 	return present;
   204 	}
   205 
   206 /**
   207 	Compares the specified component against the one in the authority passed in.
   208 	
   209 	@since			6.0
   210 	@deprecated Deprecated in 9.1
   211 	@param			aAuthority	The authority to compare components against.
   212 	@param			aComponent	The enum specifying the component to compare.
   213 	@return			An integer value of zero if the components are the same, any other
   214 	value if the components are not the same.
   215  */
   216 EXPORT_C TInt TAuthorityC16::Compare(const TAuthorityC16& aAuthority, TAuthorityComponent aComponent) const
   217 	{
   218 	__ASSERT_ALWAYS(aComponent<EAuthorityMaxComponents && aComponent >EAuthorityComplete, User::Panic(KAuthorityPanicCategory(), KUriUtilsErrBadComponentIndex));
   219 
   220 	// Does the component exist in both the Authoritys
   221 	if( IsPresent(aComponent) && aAuthority.IsPresent(aComponent) )
   222 		{
   223 		if( aComponent == EAuthorityHost )
   224 			{
   225 			// Do case insensitive compare for host
   226 			return (iComponent[aComponent].CompareF(aAuthority.iComponent[aComponent]));
   227 			}
   228 		else
   229 			{
   230 			// Do case sensitive compare for all other components
   231 			return (iComponent[aComponent].Compare(aAuthority.iComponent[aComponent]));
   232 			}
   233 		}
   234 	else
   235 		return KErrNotFound;
   236 	}
   237 
   238 /**
   239 	Retrieves the descriptor for the entire authority.
   240 	
   241 	@since			6.0
   242 	@deprecated Deprecated in 9.1
   243 	@return			A const reference to a descriptor pointer to the authority.
   244  */
   245 EXPORT_C const TDesC16& TAuthorityC16::AuthorityDes() const
   246 	{
   247 	return iAuthorityDes;
   248 	}
   249 	
   250 /** 
   251 	Create a new HBufC descriptor containing the desired component or the full authority.
   252 	
   253 	@param   aComponent   The component to convert into Unicode (EAuthorityScheme - EAuthorityFragment), 
   254 				the full authority (EAuthorityComplete -- the default), or the final segment of the path (EAuthorityTail).
   255 	@return     the descriptor containing the desired component. 
   256 	@deprecated     Deprecated in 9.1. Provided for compatibility.
   257  */
   258 EXPORT_C HBufC* TAuthorityC16::DisplayFormL(TAuthorityComponent aComponent) const
   259 	{
   260 	TPtrC component;
   261 	if ( aComponent == EAuthorityComplete) // extract the full authority
   262 		{
   263 		component.Set(iAuthorityDes);
   264 		}
   265 	else
   266 		{ // extract the specified component, will Panic if invalid
   267 		component.Set( Extract(aComponent) );
   268 	}
   269 
   270 	return component.AllocL();
   271 	}
   272 
   273 /**
   274 	@internalComponent
   275 	Resets the descriptor pointers for the authority components and the authority.
   276 	
   277 	@since			6.0
   278 	@deprecated Deprecated in 9.1
   279 	@post			All authority component information is removed and the authority 
   280 	descriptor is set to NULL.
   281  */
   282 void TAuthorityC16::Reset()
   283 	{
   284 	// Set descriptor pointers to NULL and lengths to zero
   285 	for( TInt i=0; i<EAuthorityMaxComponents; ++i )
   286 		{
   287 		iComponent[i].Set(NULL,0);
   288 		}
   289 	iAuthorityDes.Set(NULL,0);
   290 	}
   291