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