1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/httputils/DelimitedParser/CDelimitedPath.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,330 @@
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 <delimitedpath8.h>
1.20 +#include <delimitedpath16.h>
1.21 +#include <escapeutils.h>
1.22 +
1.23 +//
1.24 +//
1.25 +// Implemetation of CDelimitedPath8
1.26 +//
1.27 +//
1.28 +
1.29 +/**
1.30 + Static factory constructor. Uses two phase construction and leaves
1.31 + nothing on the CleanupStack.
1.32 +
1.33 + @param aPath A descriptor with the initial path.
1.34 + @return A pointer to the newly created object.
1.35 + */
1.36 +EXPORT_C CDelimitedPath8* CDelimitedPath8::NewL(const TDesC8& aPath)
1.37 + {
1.38 + CDelimitedPath8* self = NewLC(aPath);
1.39 + CleanupStack::Pop(self);
1.40 + return self;
1.41 + }
1.42 +
1.43 +/**
1.44 + Static factory constructor. Uses two phase construction and leaves a pointer
1.45 + to created object on the CleanupStack.
1.46 +
1.47 + @param aPath A descriptor with the initial path.
1.48 + @return A pointer to the newly created object.
1.49 + */
1.50 +EXPORT_C CDelimitedPath8* CDelimitedPath8::NewLC(const TDesC8& aPath)
1.51 + {
1.52 + CDelimitedPath8* self = new (ELeave) CDelimitedPath8;
1.53 + CleanupStack::PushL(self);
1.54 + self->ConstructL(aPath);
1.55 + return self;
1.56 + }
1.57 +
1.58 +/**
1.59 + Destructor.
1.60 +*/
1.61 +EXPORT_C CDelimitedPath8::~CDelimitedPath8()
1.62 + {
1.63 + }
1.64 +
1.65 +/**
1.66 + Escape encodes the segment then inserts the escaped version in a position before
1.67 + the current parsed segment. The new segment should only contain a single path segment,
1.68 + as any path delimiters in the segment will be converted to an escape triple.
1.69 + The parser is left in a state where its current segment is the same one as before the insertion.
1.70 +
1.71 + @pre The path must have been initially parsed.
1.72 + @param aSegment A descriptor with the unescaped path segment.
1.73 + @post The path will have been extended to include the new segment.
1.74 + The current segment will remain as the one before the insertion.
1.75 + */
1.76 +EXPORT_C void CDelimitedPath8::InsertAndEscapeCurrentL(const TDesC8& aSegment)
1.77 + {
1.78 + // Create escaped version of the segment
1.79 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
1.80 + CleanupStack::PushL(escaped);
1.81 +
1.82 + // Insert the segment
1.83 + InsertCurrentL(*escaped);
1.84 +
1.85 + // Cleanup
1.86 + CleanupStack::PopAndDestroy(escaped);
1.87 + }
1.88 +
1.89 +/**
1.90 + Escape encodes the segment then inserts the escaped version at the back of the path.
1.91 + The new segment should only contain a single path segment, as any path delimiters in
1.92 + the segment will be converted to an escape triple. The parser is left in a state
1.93 + where its current segment is the same one as before the insertion.
1.94 +
1.95 + @pre The delimiter must have been set.
1.96 + @param aSegment A descriptor with the unescaped path segment.
1.97 + @post The path will have been extended to include the new segment
1.98 + */
1.99 +EXPORT_C void CDelimitedPath8::PushAndEscapeBackL(const TDesC8& aSegment)
1.100 + {
1.101 + // Create escaped version of the segment
1.102 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
1.103 + CleanupStack::PushL(escaped);
1.104 +
1.105 + // Insert the segment
1.106 + PushBackL(*escaped);
1.107 +
1.108 + // Cleanup
1.109 + CleanupStack::PopAndDestroy(escaped);
1.110 + }
1.111 +
1.112 +/**
1.113 + Escape encodes the segment then inserts the escaped version at the front of the path.
1.114 + The new segment should only contain a single path segment, as any path delimiters in
1.115 + the segment will be converted to an escape triple. The parser is left in a state where
1.116 + its current segment is the same one as before the insertion.
1.117 +
1.118 + @pre The delimiter must have been set.
1.119 + @param aSegment A descriptor with the unescaped path segment.
1.120 + @post The path will have been extended to include the new segment
1.121 + */
1.122 +EXPORT_C void CDelimitedPath8::PushAndEscapeFrontL(const TDesC8& aSegment)
1.123 + {
1.124 + // Create escaped version of the segment
1.125 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapePath);
1.126 + CleanupStack::PushL(escaped);
1.127 +
1.128 + // Insert the segment
1.129 + PushFrontL(*escaped);
1.130 +
1.131 + // Cleanup
1.132 + CleanupStack::PopAndDestroy(escaped);
1.133 + }
1.134 +
1.135 +/**
1.136 + Constructor.
1.137 +*/
1.138 +CDelimitedPath8::CDelimitedPath8()
1.139 +: CDelimitedDataBase8()
1.140 + {
1.141 + }
1.142 +
1.143 +/**
1.144 + Second phase of two-phase construction method. Does any allocations required to fully construct
1.145 + the object.
1.146 +
1.147 + @param aPath A descriptor with the initial string.
1.148 + @pre First phase of construction is complete.
1.149 + @post The object is fully constructed.
1.150 +*/
1.151 +void CDelimitedPath8::ConstructL(const TDesC8& aPath)
1.152 + {
1.153 + // Call base class ConstructL()
1.154 + CDelimitedDataBase8::ConstructL(aPath);
1.155 +
1.156 + // Set the delimiter to '/'
1.157 + SetDelimiter(TChar('/'));
1.158 + }
1.159 +
1.160 +//
1.161 +//
1.162 +// Implemetation of CDelimitedPath16
1.163 +//
1.164 +//
1.165 +
1.166 +/**
1.167 + Static factory constructor. Uses two phase construction and leaves nothing on
1.168 + the CleanupStack.
1.169 +
1.170 + @since 6.0
1.171 + @param aPath A descriptor with the initial path.
1.172 + @return A pointer to created object.
1.173 + @post Nothing left on the CleanupStack.
1.174 + */
1.175 +EXPORT_C CDelimitedPath16* CDelimitedPath16::NewL(const TDesC16& aPath)
1.176 + {
1.177 + CDelimitedPath16* self = NewLC(aPath);
1.178 + CleanupStack::Pop(self);
1.179 + return self;
1.180 + }
1.181 +
1.182 +/**
1.183 + Static factory constructor. Uses two phase construction and leaves a pointer to
1.184 + created object on the CleanupStack.
1.185 +
1.186 + @since 6.0
1.187 + @param aPath A descriptor with the initial path.
1.188 + @return A pointer to created object.
1.189 + @post Pointer to created object left of CleanupStack.
1.190 +*/
1.191 +EXPORT_C CDelimitedPath16* CDelimitedPath16::NewLC(const TDesC16& aPath)
1.192 + {
1.193 + CDelimitedPath16* self = new (ELeave) CDelimitedPath16;
1.194 + CleanupStack::PushL(self);
1.195 + self->ConstructL(aPath);
1.196 + return self;
1.197 + }
1.198 +
1.199 +/**
1.200 + Destructor.
1.201 +
1.202 + @since 6.0
1.203 +*/
1.204 +EXPORT_C CDelimitedPath16::~CDelimitedPath16()
1.205 + {
1.206 + }
1.207 +
1.208 +/**
1.209 + Escape encodes the segment then inserts the escaped version in a position before the
1.210 + current parsed segment. The new segment should only contain a single path segment, as
1.211 + any path delimiters in the segment will be converted to an escape triple. The parser
1.212 + is left in a state where its current segment is the same one as before the insertion.
1.213 +
1.214 + @since 6.0
1.215 + @param aSegment A descriptor with the unescaped path segment.
1.216 + @pre The path must have been initially parsed.
1.217 + @post The path will have been extended to include the new segment. The
1.218 + current segment will remain as the one before the insertion.
1.219 +*/
1.220 +EXPORT_C void CDelimitedPath16::InsertAndEscapeCurrentL(const TDesC16& aSegment)
1.221 + {
1.222 + // Need to convert to utf8 first
1.223 + HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
1.224 + CleanupStack::PushL(utf8);
1.225 +
1.226 + // Create escaped version of component
1.227 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
1.228 + CleanupStack::PushL(escaped);
1.229 +
1.230 + // Convert back to 16-bits
1.231 + HBufC16* converted = HBufC16::NewLC(escaped->Length());
1.232 + converted->Des().Copy(*escaped);
1.233 +
1.234 + // Insert the segment
1.235 + InsertCurrentL(*converted);
1.236 +
1.237 + // Cleanup
1.238 + CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
1.239 + }
1.240 +
1.241 +/**
1.242 + Escape encodes the segment then inserts the escaped version at the back of the path.
1.243 + The new segment should only contain a single path segment, as any path delimiters in
1.244 + the segment will be converted to an escape triple. The parser is left in a state where
1.245 + its current segment is the same one as before the insertion.
1.246 +
1.247 + @warning A re-parse is required to ensure that the parser is valid.
1.248 + @since 6.0
1.249 + @param aSegment A descriptor with the unescaped path segment.
1.250 + @pre The delimiter must have been set.
1.251 + @post The path will have been extended to include the new segment.
1.252 +*/
1.253 +EXPORT_C void CDelimitedPath16::PushAndEscapeBackL(const TDesC16& aSegment)
1.254 + {
1.255 + // Need to convert to utf8 first
1.256 + HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
1.257 + CleanupStack::PushL(utf8);
1.258 +
1.259 + // Create escaped version of component
1.260 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
1.261 + CleanupStack::PushL(escaped);
1.262 +
1.263 + // Convert back to 16-bits
1.264 + HBufC16* converted = HBufC16::NewLC(escaped->Length());
1.265 + converted->Des().Copy(*escaped);
1.266 +
1.267 + // Insert the segment
1.268 + PushBackL(*converted);
1.269 +
1.270 + // Cleanup
1.271 + CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
1.272 + }
1.273 +
1.274 +/**
1.275 + Escape encodes the segment then inserts the escaped version at the front of the path.
1.276 + The new segment should only contain a single path segment, as any path delimiters in
1.277 + the segment will be converted to an escape triple. The parser is left in a state where
1.278 + its current segment is the same one as before the insertion.
1.279 +
1.280 + @warning A re-parse is required to ensure that the parser is valid.
1.281 + @since 6.0
1.282 + @param aSegment A descriptor with the unescaped path segment.
1.283 + @pre The delimiter must have been set.
1.284 + @post The path will have been extended to include the new segment.
1.285 +*/
1.286 +EXPORT_C void CDelimitedPath16::PushAndEscapeFrontL(const TDesC16& aSegment)
1.287 + {
1.288 + // Need to convert to utf8 first
1.289 + HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
1.290 + CleanupStack::PushL(utf8);
1.291 +
1.292 + // Create escaped version of component
1.293 + HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
1.294 + CleanupStack::PushL(escaped);
1.295 +
1.296 + // Convert back to 16-bits
1.297 + HBufC16* converted = HBufC16::NewLC(escaped->Length());
1.298 + converted->Des().Copy(*escaped);
1.299 +
1.300 + // Insert the segment
1.301 + PushFrontL(*converted);
1.302 +
1.303 + // Cleanup
1.304 + CleanupStack::PopAndDestroy(3, utf8); // utf8, escaped, converted
1.305 + }
1.306 +
1.307 +/**
1.308 + Constructor. First phase of two-phase construction method. Does non-allocating construction.
1.309 +
1.310 + @since 6.0
1.311 +*/
1.312 +CDelimitedPath16::CDelimitedPath16()
1.313 +: CDelimitedDataBase16()
1.314 + {
1.315 + }
1.316 +
1.317 +/**
1.318 + Second phase of two-phase construction method. Does any allocations required to fully construct
1.319 + the object.
1.320 +
1.321 + @since 6.0
1.322 + @param aPath A descriptor with the initial path.
1.323 + @pre First phase of construction is complete.
1.324 + @post The object is fully constructed.
1.325 +*/
1.326 +void CDelimitedPath16::ConstructL(const TDesC16& aPath)
1.327 + {
1.328 + // Call base class ConstructL()
1.329 + CDelimitedDataBase16::ConstructL(aPath);
1.330 +
1.331 + // Set the delimiter to '/'
1.332 + SetDelimiter(TChar('/'));
1.333 + }