1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/AuthorityParser/CAuthority.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,648 @@
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 "CAuthorityInternal.h"
1.22 +#include <uriutilscommon.h>
1.23 +#include <escapeutils.h>
1.24 +#include <uriutils.h>
1.25 +
1.26 +
1.27 +//
1.28 +//
1.29 +// Implementation of CAuthority8
1.30 +//
1.31 +//
1.32 +
1.33 +/**
1.34 + Static factory constructor. Uses two phase construction and leaves nothing on the
1.35 + CleanupStack. Creates an authority object which is a copy of the input parameter
1.36 + aAuthority.
1.37 +
1.38 + @since 6.0
1.39 + @param aAuthority A reference to a parsed authority object.
1.40 + @return A pointer to the newly created CAuthority8 object.
1.41 + @post A fully constructed and initialized CAuthority8 object.
1.42 +*/
1.43 +EXPORT_C CAuthority8* CAuthority8::NewL(const TAuthorityC8& aAuthority)
1.44 + {
1.45 + CAuthority8* self = CAuthority8::NewLC(aAuthority);
1.46 + CleanupStack::Pop(self);
1.47 + return self;
1.48 + }
1.49 +
1.50 +/**
1.51 + Static factory constructor. Uses two phase construction and leaves a pointer to created
1.52 + object on the CleanupStack. Creates an authority object which is a copy of the input
1.53 + parameter aAuthority.
1.54 +
1.55 + @since 6.0
1.56 + @param aAuthority A reference to a parsed authority object.
1.57 + @return A pointer to the newly created CAuthority8 object.
1.58 + @post A fully constructed and initialized CAuthority8 object.
1.59 + */
1.60 +EXPORT_C CAuthority8* CAuthority8::NewLC(const TAuthorityC8& aAuthority)
1.61 + {
1.62 + CAuthority8* self = new (ELeave) CAuthority8(aAuthority);
1.63 + CleanupStack::PushL(self);
1.64 + self->ConstructL();
1.65 + return self;
1.66 + }
1.67 +
1.68 +/**
1.69 + Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
1.70 + Creates an authority object which is empty.
1.71 +
1.72 + @since 6.0
1.73 + @return A pointer to the newly created CAuthority8 object.
1.74 + @post A fully constructed and initialized CAuthority8 object.
1.75 + */
1.76 +EXPORT_C CAuthority8* CAuthority8::NewL()
1.77 + {
1.78 + CAuthority8* self = CAuthority8::NewLC();
1.79 + CleanupStack::Pop(self);
1.80 + return self;
1.81 + }
1.82 +
1.83 +/**
1.84 + Static factory constructor. Uses two phase construction and leaves a pointer to created object on
1.85 + the CleanupStack. Creates an authority object which is empty.
1.86 +
1.87 + @since 6.0
1.88 + @return A pointer to the newly created CAuthority8 object.
1.89 + @post A fully constructed and initialized CAuthority8 object.
1.90 + */
1.91 +EXPORT_C CAuthority8* CAuthority8::NewLC()
1.92 + {
1.93 + CAuthority8* self = new (ELeave) CAuthority8(TAuthorityC8());
1.94 + CleanupStack::PushL(self);
1.95 + self->ConstructL();
1.96 + return self;
1.97 + }
1.98 +
1.99 +/**
1.100 + Destructor.
1.101 +
1.102 + @since 6.0
1.103 + */
1.104 +EXPORT_C CAuthority8::~CAuthority8()
1.105 + {
1.106 + delete iAuthorityBuf;
1.107 + }
1.108 +
1.109 +/**
1.110 + Provides a reference to the parsed authority. Allows access to the non-modifying API for TAuthorityC8.
1.111 +
1.112 + @since 6.0
1.113 + @return A const reference to the parsed authority object.
1.114 + */
1.115 +EXPORT_C const TAuthorityC8& CAuthority8::Authority() const
1.116 + {
1.117 + return iAuthority;
1.118 + }
1.119 +
1.120 +/**
1.121 + Sets the specified component in the authority. The component is set to the value given in the argument
1.122 + aData. If the specified component already exists then it is replaced with the new value.
1.123 +
1.124 + @since 6.0
1.125 + @param aData A descriptor pointer to the new value for the authority component.
1.126 + @param aComponent An enum specifying the component to be set.
1.127 + @pre Object is fully constructed.
1.128 + @post The authority has the specified component set to the new value.
1.129 + @Leave KErrArgument If aComponent goes out of range.
1.130 + */
1.131 +EXPORT_C void CAuthority8::SetComponentL(const TDesC8& aData, TAuthorityComponent aComponent)
1.132 + {
1.133 + // Update the appropriate component table entry
1.134 + iAuthority.iComponent[aComponent].Set(aData);
1.135 +
1.136 + // Copy to the buffer by forming the Authority
1.137 + FormAuthorityL();
1.138 + }
1.139 +
1.140 +/**
1.141 + Escape encodes the component then sets the specified component in the authority. The component is set to the
1.142 + value given in the argument aData. If the specified component already exists then it is replaced with the new
1.143 + value.
1.144 +
1.145 + @since 6.0
1.146 + @param aData A descriptor pointer to the new value for the authority component.
1.147 + @param aComponent An enum specifying the component to be set.
1.148 + @pre Object is fully constructed.
1.149 + @post The authority has the specified component set to the new value.
1.150 + */
1.151 +EXPORT_C void CAuthority8::SetAndEscapeComponentL(const TDesC8& aData, TAuthorityComponent aComponent)
1.152 + {
1.153 + // Create escaped version of component
1.154 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(aData, EscapeUtils::EEscapeAuth);
1.155 + CleanupStack::PushL(escaped);
1.156 +
1.157 + // Set the component
1.158 + if(aComponent<EAuthorityMaxComponents && aComponent >=EAuthorityUserinfo )
1.159 + {
1.160 + SetComponentL(*escaped, aComponent);
1.161 + }
1.162 + else
1.163 + {
1.164 + User::Leave(KErrArgument);
1.165 + }
1.166 +
1.167 + // Cleanup
1.168 + CleanupStack::PopAndDestroy(escaped);
1.169 + }
1.170 +
1.171 +/**
1.172 + Removes the specified component from the authority. If the component does not exist then this function does
1.173 + nothing.
1.174 +
1.175 + @since 6.0
1.176 + @param aComponent An enum specifying the component to be removed.
1.177 + @pre Object is fully constructed.
1.178 + @post The authority is updated to exclude the specified component.
1.179 + */
1.180 +EXPORT_C void CAuthority8::RemoveComponentL(TAuthorityComponent aComponent)
1.181 + {
1.182 + if( iAuthority.IsPresent(aComponent) )
1.183 + {
1.184 + // Remove the component - set pointer to NULL and length to zero
1.185 + iAuthority.iComponent[aComponent].Set(NULL,0);
1.186 +
1.187 + // Re-form buffer and component table
1.188 + FormAuthorityL();
1.189 + }
1.190 + }
1.191 +
1.192 +/**
1.193 + Constructor. First phase of two-phase construction method. Does non-allocating construction.
1.194 +
1.195 + @param aNewAuthority The parsed authority component information from which
1.196 + to create the authority.
1.197 + @since 6.0
1.198 + */
1.199 +CAuthority8::CAuthority8(const TAuthorityC8& aNewAuthority)
1.200 +: CBase(), iAuthority(aNewAuthority)
1.201 + {
1.202 + }
1.203 +
1.204 +/**
1.205 + Second phase of two-phase construction method. Does any allocations required to fully construct
1.206 + the object.
1.207 +
1.208 + @since 6.0
1.209 + @pre First phase of construction is complete.
1.210 + @post The object is fully constructed and initialized.
1.211 + */
1.212 +void CAuthority8::ConstructL()
1.213 + {
1.214 + // Create the HBufC8
1.215 + FormAuthorityL();
1.216 + }
1.217 +
1.218 +/**
1.219 + Forms the authority from the parsed authority information. A copy of the parsed authority is created.
1.220 + The parsed authority is changed to refer to the copy.
1.221 +
1.222 + @since 6.0
1.223 + @pre The parsed authority information is set.
1.224 + @post The authority buffer is a copy of the parsed authority, and the
1.225 + parsed authority now refers to the copy.
1.226 + */
1.227 +void CAuthority8::FormAuthorityL()
1.228 + {
1.229 + TBool isIPv6Host;
1.230 +
1.231 + // Calculate length of of the Authority
1.232 + TInt length = CalculateAuthorityLength(iAuthority.iComponent, isIPv6Host);
1.233 +
1.234 + // Create a temporary buffer and descriptor pointer to it
1.235 + HBufC8* buf = HBufC8::NewL(length);
1.236 + TPtr8 authority = buf->Des();
1.237 +
1.238 + // Create the authority, updating the internal authority object
1.239 + DoFormAuthority(authority, iAuthority.iComponent, isIPv6Host);
1.240 +
1.241 + // Update the internal buffer and descriptor pointer for the authority object
1.242 + delete iAuthorityBuf;
1.243 + iAuthorityBuf = buf;
1.244 + iAuthority.iAuthorityDes.Set(iAuthorityBuf->Des());
1.245 + }
1.246 +
1.247 +//
1.248 +//
1.249 +// Implementation of CAuthority16
1.250 +//
1.251 +//
1.252 +
1.253 +/**
1.254 + Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
1.255 + Creates an authority object which is a copy of the input parameter aAuthority.
1.256 +
1.257 + @since 6.0
1.258 + @deprecated Deprecated in 9.1
1.259 + @param aAuthority A reference to a parsed authority object.
1.260 + @return A pointer to the newly created CAuthority16 object.
1.261 + @post A fully constructed and initialized CAuthority16 object.
1.262 + */
1.263 +EXPORT_C CAuthority16* CAuthority16::NewL(const TAuthorityC16& aAuthority)
1.264 + {
1.265 + CAuthority16* self = CAuthority16::NewLC(aAuthority);
1.266 + CleanupStack::Pop(self);
1.267 + return self;
1.268 + }
1.269 +
1.270 +/**
1.271 + Static factory constructor. Uses two phase construction and leaves a pointer to created object on
1.272 + the CleanupStack. Creates an authority object which is a copy of the input parameter aAuthority.
1.273 +
1.274 + @since 6.0
1.275 + @deprecated Deprecated in 9.1
1.276 + @param aAuthority A reference to a parsed authority object.
1.277 + @return A pointer to the newly created CAuthority16 object.
1.278 + @post A fully constructed and initialized CAuthority16 object.
1.279 + */
1.280 +EXPORT_C CAuthority16* CAuthority16::NewLC(const TAuthorityC16& aAuthority)
1.281 + {
1.282 + CAuthority16* self = new (ELeave) CAuthority16(aAuthority);
1.283 + CleanupStack::PushL(self);
1.284 + self->ConstructL();
1.285 + return self;
1.286 + }
1.287 +
1.288 +/**
1.289 + Static factory constructor. Uses two phase construction and leaves nothing on the CleanupStack.
1.290 + Creates an authority object which is empty.
1.291 +
1.292 + @since 6.0
1.293 + @deprecated Deprecated in 9.1
1.294 + @return A pointer to the newly created CAuthority16 object.
1.295 + @post A fully constructed and initialized CAuthority16 object.
1.296 + */
1.297 +EXPORT_C CAuthority16* CAuthority16::NewL()
1.298 + {
1.299 + CAuthority16* self = CAuthority16::NewLC();
1.300 + CleanupStack::Pop(self);
1.301 + return self;
1.302 + }
1.303 +
1.304 +/**
1.305 + Static factory constructor. Uses two phase construction and leaves a pointer to created object on the
1.306 + CleanupStack. Creates an authority object which is empty.
1.307 +
1.308 + @since 6.0
1.309 + @deprecated Deprecated in 9.1
1.310 + @return A pointer to the newly created CAuthority16 object.
1.311 + @post A fully constructed and initialized CAuthority16 object.
1.312 + */
1.313 +EXPORT_C CAuthority16* CAuthority16::NewLC()
1.314 + {
1.315 + CAuthority16* self = new (ELeave) CAuthority16(TAuthorityC16());
1.316 + CleanupStack::PushL(self);
1.317 + self->ConstructL();
1.318 + return self;
1.319 + }
1.320 +
1.321 +/**
1.322 + Destructor.
1.323 +
1.324 + @since 6.0
1.325 + @deprecated Deprecated in 9.1
1.326 + */
1.327 +EXPORT_C CAuthority16::~CAuthority16()
1.328 + {
1.329 + delete iAuthorityBuf;
1.330 + }
1.331 +
1.332 +/**
1.333 + Provides a reference to the parsed authority. Allows access to the non-modifying API for TAuthorityC.
1.334 +
1.335 + @since 6.0
1.336 + @deprecated Deprecated in 9.1
1.337 + @return A const reference to the parsed authority object.
1.338 + */
1.339 +EXPORT_C const TAuthorityC16& CAuthority16::Authority() const
1.340 + {
1.341 + return iAuthority;
1.342 + }
1.343 +
1.344 +/**
1.345 + Sets the specified component in the authority. The component is set to the value given in the argument aData.
1.346 + If the specified component already exists then it is replaced with the new value.
1.347 +
1.348 + @since 6.0
1.349 + @deprecated Deprecated in 9.1
1.350 + @param aData A descriptor pointer to the new value for the authority component.
1.351 + @param aComponent An enum specifying the component to be set.
1.352 + @pre Object is fully constructed.
1.353 + @post The authority has the specified component set to the new value.
1.354 + @Leave KErrArgument If aComponent goes out of range.
1.355 + */
1.356 +EXPORT_C void CAuthority16::SetComponentL(const TDesC16& aData, TAuthorityComponent aComponent)
1.357 + {
1.358 + // Update the appropriate component table entry
1.359 + iAuthority.iComponent[aComponent].Set(aData);
1.360 +
1.361 + // Copy to the buffer by forming the Authority
1.362 + FormAuthorityL();
1.363 + }
1.364 +
1.365 +/**
1.366 + Escape encodes the component then sets the specified component in the authority. The component is set to the
1.367 + value given in the argument aData. If the specified component already exists then it is replaced with the new
1.368 + value.
1.369 +
1.370 + @since 6.0
1.371 + @deprecated Deprecated in 9.1
1.372 + @param aData A descriptor pointer to the new value for the authority component.
1.373 + @param aComponent An enum specifying the component to be set.
1.374 + @pre Object is fully constructed.
1.375 + @post The authority has the specified component set to the new value.
1.376 + */
1.377 +EXPORT_C void CAuthority16::SetAndEscapeComponentL(const TDesC16& aData, TAuthorityComponent aComponent)
1.378 + {
1.379 + // Need to convert to utf8 first
1.380 + HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aData);
1.381 + CleanupStack::PushL(utf8);
1.382 +
1.383 + // Create escaped version of component
1.384 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapeAuth);
1.385 + CleanupStack::PushL(escaped);
1.386 +
1.387 + // Convert back to 16-bits
1.388 + HBufC16* converted = HBufC16::NewLC(escaped->Length());
1.389 + converted->Des().Copy(*escaped);
1.390 +
1.391 + // Set the component
1.392 + if(aComponent<EAuthorityMaxComponents && aComponent >=EAuthorityUserinfo )
1.393 + {
1.394 + SetComponentL(*converted, aComponent);
1.395 + }
1.396 + else
1.397 + {
1.398 + User::Leave(KErrArgument);
1.399 + }
1.400 +
1.401 + // Cleanup
1.402 + CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
1.403 + }
1.404 +
1.405 +/**
1.406 + Removes the specified component from the authority. If the component does not exist then this
1.407 + function does nothing.
1.408 +
1.409 + @since 6.0
1.410 + @deprecated Deprecated in 9.1
1.411 + @param aComponent An enum specifying the component to be removed.
1.412 + @pre Object is fully constructed.
1.413 + @post The authority is updated to exclude the specified component.
1.414 + */
1.415 +EXPORT_C void CAuthority16::RemoveComponentL(TAuthorityComponent aComponent)
1.416 + {
1.417 + if( iAuthority.IsPresent(aComponent) )
1.418 + {
1.419 + // Remove the component - set pointer to NULL and length to zero
1.420 + iAuthority.iComponent[aComponent].Set(NULL,0);
1.421 +
1.422 + // Re-form buffer and component table
1.423 + FormAuthorityL();
1.424 + }
1.425 + }
1.426 +
1.427 +/**
1.428 + Constructor. First phase of two-phase construction method. Does non-allocating construction.
1.429 +
1.430 + @since 6.0
1.431 + @param aNewAuthority The parsed authority component information from which
1.432 + to create the authority.
1.433 + */
1.434 +CAuthority16::CAuthority16(const TAuthorityC16& aNewAuthority)
1.435 +: CBase(), iAuthority(aNewAuthority)
1.436 + {
1.437 + }
1.438 +
1.439 +/**
1.440 + Second phase of two-phase construction method. Does any allocations required to fully construct
1.441 + the object.
1.442 +
1.443 + @since 6.0
1.444 + @pre First phase of construction is complete.
1.445 + @post The object is fully constructed and initialized.
1.446 + */
1.447 +void CAuthority16::ConstructL()
1.448 + {
1.449 + // Create the HBufC16
1.450 + FormAuthorityL();
1.451 + }
1.452 +
1.453 +/**
1.454 + Forms the authority from the parsed authority information. A copy of the parsed authority is created.
1.455 + The parsed authority is changed to refer to the copy.
1.456 +
1.457 + @since 6.0
1.458 + @pre The parsed authority information is set.
1.459 + @post The authority buffer is a copy of the parsed authority, and the
1.460 + parsed authority now refers to the copy.
1.461 + */
1.462 +void CAuthority16::FormAuthorityL()
1.463 + {
1.464 + TBool isIPv6Host;
1.465 +
1.466 + // Calculate length of of the Authority
1.467 + TInt length = CalculateAuthorityLength(iAuthority.iComponent, isIPv6Host);
1.468 +
1.469 + // Create a temporary buffer and descriptor pointer to it
1.470 + HBufC16* buf = HBufC16::NewL(length);
1.471 + TPtr16 authority = buf->Des();
1.472 +
1.473 + // Create the authority, updating the internal authority object
1.474 + DoFormAuthority(authority, iAuthority.iComponent, isIPv6Host);
1.475 +
1.476 + // Update the internal buffer and descriptor pointer for the authority object
1.477 + delete iAuthorityBuf;
1.478 + iAuthorityBuf = buf;
1.479 + iAuthority.iAuthorityDes.Set(iAuthorityBuf->Des());
1.480 + }
1.481 +
1.482 +//
1.483 +//
1.484 +// Implementation of templated LOCAL functions
1.485 +//
1.486 +//
1.487 +
1.488 +/**
1.489 + Calculates the length of the authority from a list of the components.
1.490 +
1.491 + @since 6.0
1.492 + @param aComponent The array of descriptor pointers to the authority
1.493 + components.
1.494 + @param aIsIPv6Host Specifies ETrue or EFalse.
1.495 + @return The length of the authority including the required delimiters.
1.496 +*/
1.497 +template<class TPtrCType>
1.498 +TInt CalculateAuthorityLength(const TPtrCType aComponent[], TBool& aIsIPv6Host)
1.499 + {
1.500 + aIsIPv6Host = EFalse;
1.501 + TInt length=0;
1.502 + for( TInt i=0; i<EAuthorityMaxComponents; ++i )
1.503 + {
1.504 + if( aComponent[i].Ptr() )
1.505 + {
1.506 + length += aComponent[i].Length();
1.507 + // Need to make space for a delimiter if not a host
1.508 + if( i != EAuthorityHost )
1.509 + ++length;
1.510 + else
1.511 + // Check the host type
1.512 + if (UriUtils::HostType(aComponent[i]) == UriUtils::EIPv6Host)
1.513 + {
1.514 + // If its an IPv6 format host, need to increase the length for the []
1.515 + aIsIPv6Host = ETrue;
1.516 + length+=2;
1.517 + }
1.518 + }
1.519 + }
1.520 + return length;
1.521 + }
1.522 +
1.523 +/**
1.524 + Templated function to form an authority. The new authority component information is given by
1.525 + the input/output argument aComponent. For each authority component that exists in aComponent,
1.526 + that component and its appropriate delimiters are appended to aAuthority. Then the components
1.527 + in aComponent are updated to refer to the copied versions in aUri.
1.528 +
1.529 + @since 6.0
1.530 + @param aAuthority The descriptor pointer to buffer to be appended.
1.531 + @param aComponent The array of descriptor pointers to be copied and
1.532 + then updated.
1.533 + @param aIsIPv6Host Specifies ETrue or EFalse.
1.534 + @pre The buffer pointed to by aAuthority should be large enough
1.535 + to have the authority components given in aNewComponent copied into it, as well as
1.536 + the required delimiters.
1.537 + @post The authority buffer will have a copy of the authority defined in
1.538 + aNewComponent, and aOldComponent will refer to copies of these components in aAuthority.
1.539 +*/
1.540 +template<class TPtrType, class TPtrCType>
1.541 +void DoFormAuthority(TPtrType& aAuthority, TPtrCType aComponent[], const TBool& aIsIPv6Host)
1.542 + {
1.543 + if( aComponent[EAuthorityUserinfo].Ptr() )
1.544 + {
1.545 + // Update the userinfo
1.546 + SetUserinfo(aAuthority, aComponent[EAuthorityUserinfo]);
1.547 + }
1.548 + if( aComponent[EAuthorityHost].Ptr() )
1.549 + {
1.550 + // Update the host
1.551 + SetHost(aAuthority, aComponent[EAuthorityHost], aIsIPv6Host);
1.552 + }
1.553 + if( aComponent[EAuthorityPort].Ptr() )
1.554 + {
1.555 + // Update the port
1.556 + SetPort(aAuthority, aComponent[EAuthorityPort]);
1.557 + }
1.558 + }
1.559 +
1.560 +/**
1.561 + Templated function to set the userinfo in an authority. The output argument aAuthority points to
1.562 + the descriptor buffer into which aNewUserInfo will be copied. The argument aOldUserInfo is updated
1.563 + to point to the copied version of aNewUserInfo in aAuthority.
1.564 +
1.565 + @warning This function will panic with KAuthorityErrBufferOverflow if there is not
1.566 + enough space in the descriptor to append the component and any required delimiters.
1.567 + @since 6.0
1.568 + @param aAuthority The descriptor pointer to buffer to be appended.
1.569 + @param aUserinfo The descriptor pointer to the userinfo component to be copied
1.570 + and then updated.
1.571 + @pre The buffer pointed to by aAuthority should be large enough to have
1.572 + aNewUserInfo appended to it with the required delimiter.
1.573 + @post The authority buffer now includes aNewUserInfo and aOldUserInfo points
1.574 + to the copy of the userinfo component in aAuthority.
1.575 +*/
1.576 +template<class TPtrType, class TPtrCType>
1.577 +void SetUserinfo(TPtrType& aAuthority, TPtrCType& aUserinfo)
1.578 + {
1.579 + // Append the userinfo and delimiter
1.580 + aAuthority.Append(aUserinfo);
1.581 + aAuthority.Append(KUserinfoDelimiter);
1.582 +
1.583 + // Update the component table
1.584 + aUserinfo.Set(aAuthority.Left(aUserinfo.Length()));
1.585 + }
1.586 +
1.587 +/**
1.588 + Templated function to set the host in an authority. The output argument aAuthority points to the
1.589 + descriptor buffer into which aNewHost will be copied. The argument aOldHost is updated to point to
1.590 + the copied version of aNewHost in aAuthority.
1.591 +
1.592 + @warning This function will panic with KAuthorityErrBufferOverflow if there is not
1.593 + enough space in the descriptor to append the component and any required delimiters.
1.594 + @since 6.0
1.595 + @param aAuthority The descriptor pointer to buffer to appended.
1.596 + @param aHost The descriptor pointer to the host component to be copied
1.597 + and then updated.
1.598 + @param aIsIPv6Host Specifies ETrue or EFalse.
1.599 + @pre The buffer pointed to by aAuthority should be large enough to have
1.600 + aNewHost appended to it with the required delimiter.
1.601 + @post The authority buffer now includes aNewHost and aOldHost points to the
1.602 + copy of the host component in aAuthority.
1.603 +*/
1.604 +template<class TPtrType, class TPtrCType>
1.605 +void SetHost(TPtrType& aAuthority, TPtrCType& aHost, const TBool& aIsIPv6Host)
1.606 + {
1.607 + if (aIsIPv6Host)
1.608 + {
1.609 + aAuthority.Append(KIPv6UriOpenBrace);
1.610 + aAuthority.Append(aHost);
1.611 + aAuthority.Append(KIPv6UriCloseBrace);
1.612 +
1.613 + // Position = (length of uri - length of host) - length of end brace
1.614 + aHost.Set( aAuthority.Mid((aAuthority.Length()-aHost.Length())-1, aHost.Length()) );
1.615 + }
1.616 + else
1.617 + {
1.618 + // Append the host
1.619 + aAuthority.Append(aHost);
1.620 +
1.621 + // Update the component table
1.622 + aHost.Set(aAuthority.Right(aHost.Length()));
1.623 + }
1.624 + }
1.625 +
1.626 +/**
1.627 + Templated function to set the port in an authority. The output argument aAuthority points to the
1.628 + descriptor buffer into which aNewPort will be copied. The argument aOldPort is updated to point to
1.629 + the copied version of aNewPort in aAuthority.
1.630 +
1.631 + @warning This function will panic with KAuthorityErrBufferOverflow if there is not
1.632 + enough space in the descriptor to append the component and any required delimiters.
1.633 + @since 6.0
1.634 + @param aAuthority The descriptor pointer to buffer to appended.
1.635 + @param aPort The descriptor pointer to the port component to be copied
1.636 + and then updated.
1.637 + @pre The buffer pointed to by aAuthority should be large enough to have aNewPort
1.638 + appended to it with the required delimiter.
1.639 + @post The authority buffer now includes aNewPort and aOldPort points to the
1.640 + copy of the port component in aAuthority.
1.641 +*/
1.642 +template<class TPtrType, class TPtrCType>
1.643 +void SetPort(TPtrType& aAuthority, TPtrCType& aPort)
1.644 + {
1.645 + // Append delimiter and the port
1.646 + aAuthority.Append(KPortDelimiter);
1.647 + aAuthority.Append(aPort);
1.648 +
1.649 + // Update the component table
1.650 + aPort.Set(aAuthority.Right(aPort.Length()));
1.651 + }