os/ossrv/genericservices/httputils/DelimitedParser/CDelimitedQuery.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 <delimitedquery8.h>
    17 #include <delimitedquery16.h>
    18 #include <escapeutils.h>
    19 
    20 //
    21 //
    22 // Implemetation of CDelimitedQuery8
    23 //
    24 //
    25 
    26 /**
    27 	Static factory constructor. Uses two phase construction and leaves nothing on 
    28 	the CleanupStack.
    29 	
    30 	@since			6.0
    31 	@param			aQuery	A descriptor with the initial query.
    32 	@return			A pointer to created object.
    33 	@post			Nothing left on the CleanupStack.
    34  */
    35 EXPORT_C CDelimitedQuery8* CDelimitedQuery8::NewL(const TDesC8& aQuery)
    36 	{
    37 	CDelimitedQuery8* self = NewLC(aQuery);
    38 	CleanupStack::Pop(self);
    39 	return self;
    40 	}
    41 
    42 /**
    43 	Static factory constructor. Uses two phase construction and leaves a pointer to 
    44 	created object on the CleanupStack.
    45 	
    46 	@since			6.0
    47 	@param			aQuery	A descriptor with the initial query.
    48 	@return			A pointer to created object.
    49 	@post			Pointer to created object left of CleanupStack.
    50  */
    51 EXPORT_C CDelimitedQuery8* CDelimitedQuery8::NewLC(const TDesC8& aQuery)
    52 	{
    53 	CDelimitedQuery8* self = new (ELeave) CDelimitedQuery8;
    54 	CleanupStack::PushL(self);
    55 	self->ConstructL(aQuery);
    56 	return self;
    57 	}
    58 
    59 /**
    60 	Destructor.
    61 	
    62 	@since			6.0
    63  */
    64 EXPORT_C CDelimitedQuery8::~CDelimitedQuery8()
    65 	{
    66 	}
    67 
    68 /**
    69 	Escape encodes segment then inserts the escaped version in a position before the 
    70 	current parsed segment. The new segment should only contain a single query segment, 
    71 	as any query delimiters in the segment will be converted to an escape triple. The 
    72 	parser is left in a state where its current segment is the same one as before the 
    73 	insertion.
    74 	
    75 	@since			6.0
    76 	@param			aSegment	A descriptor with the unescaped query segment.
    77 	@pre 			The query must have been initially parsed.
    78 	@post			The query will have been extended to include the new segment. The 
    79 	current segment will remain as the one before the insertion.
    80  */
    81 EXPORT_C void CDelimitedQuery8::InsertAndEscapeCurrentL(const TDesC8& aSegment)
    82 	{
    83 	// Create escaped version of the segment
    84 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapeQuery);
    85 	CleanupStack::PushL(escaped);
    86 
    87 	// Insert the segment
    88 	InsertCurrentL(*escaped);
    89 
    90 	// Cleanup
    91 	CleanupStack::PopAndDestroy(escaped);
    92 	}
    93 
    94 /**
    95 	Escape encodes segment then inserts the escaped version at the back of the query. 
    96 	The new segment should only contain a single query segment, as any query delimiters 
    97 	in the segment will be converted to an escape triple. The parser is left in a state 
    98 	where its current segment is the same one as before the insertion.
    99 	
   100 	@warning		A re-parse is required to ensure that the parser is valid.
   101 	@since			6.0
   102 	@param			aSegment	A descriptor with the unescaped query segment.
   103 	@pre 			The delimiter must have been set. 
   104 	@post			The query will have been extended to include the new segment.
   105  */
   106 EXPORT_C void CDelimitedQuery8::PushAndEscapeBackL(const TDesC8& aSegment)
   107 	{
   108 	// Create escaped version of the segment
   109 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapeQuery);
   110 	CleanupStack::PushL(escaped);
   111 
   112 	// Insert the segment
   113 	PushBackL(*escaped);
   114 
   115 	// Cleanup
   116 	CleanupStack::PopAndDestroy(escaped);
   117 	}
   118 
   119 /**
   120 	Escape encodes segment then inserts the escaped version at the front of the query. 
   121 	The new segment should only contain a single query segment, as any query delimiters 
   122 	in the segment will be converted to an escape triple. The parser is left in a state 
   123 	where its current segment is the same one as before the insertion.
   124 	
   125 	@warning		A re-parse is required to ensure that the parser is valid.
   126 	@since			6.0
   127 	@param			aSegment	A descriptor with the unescaped query segment.
   128 	@pre 			The delimiter must have been set. 
   129 	@post			The query will have been extended to include the new segment.
   130  */
   131 EXPORT_C void CDelimitedQuery8::PushAndEscapeFrontL(const TDesC8& aSegment)
   132 	{
   133 	// Create escaped version of the segment
   134 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(aSegment, EscapeUtils::EEscapeQuery);
   135 	CleanupStack::PushL(escaped);
   136 
   137 	// Insert the segment
   138 	PushFrontL(*escaped);
   139 
   140 	// Cleanup
   141 	CleanupStack::PopAndDestroy(escaped);
   142 	}
   143 
   144 /**
   145 	Constructor. First phase of two-phase construction method. Does non-allocating 
   146 	construction.
   147 	
   148 	@since			6.0
   149  */
   150 CDelimitedQuery8::CDelimitedQuery8()
   151 : CDelimitedDataBase8()
   152 	{
   153 	}
   154 
   155 /**
   156 	Second phase of two-phase construction method. Does any allocations required to fully 
   157 	construct the object.
   158 	
   159 	@since			6.0
   160 	@param			aQuery	A descriptor with the initial query.
   161 	@pre 			First phase of construction is complete.
   162 	@post			The object is fully constructed.
   163  */
   164 void CDelimitedQuery8::ConstructL(const TDesC8& aQuery)
   165 	{
   166 	// Call base class ConstructL()
   167 	CDelimitedDataBase8::ConstructL(aQuery);
   168 
   169 	// Set the delimiter to '&'
   170 	SetDelimiter(TChar('&'));
   171 	}
   172 
   173 //
   174 //
   175 // Implemetation of CDelimitedQuery16
   176 //
   177 //
   178 
   179 /**
   180 	Static factory constructor. Uses two phase construction and leaves nothing on the 
   181 	CleanupStack.
   182 						
   183 	@since			6.0
   184 	@param			aQuery	A descriptor with the initial query.
   185 	@return			A pointer to created object.
   186 	@post			Nothing left on the CleanupStack.
   187  */
   188 EXPORT_C CDelimitedQuery16* CDelimitedQuery16::NewL(const TDesC16& aQuery)
   189 	{
   190 	CDelimitedQuery16* self = NewLC(aQuery);
   191 	CleanupStack::Pop(self);
   192 	return self;
   193 	}
   194 
   195 
   196 /**
   197 	Static factory constructor. Uses two phase construction and leaves a pointer to created object on the CleanupStack.
   198 						
   199 	@since			6.0
   200 	@param			aQuery	A descriptor with the initial query.
   201 	@return			A pointer to created object.
   202 	@post			Pointer to created object left of CleanupStack.
   203  */
   204 EXPORT_C CDelimitedQuery16* CDelimitedQuery16::NewLC(const TDesC16& aQuery)
   205 	{
   206 	CDelimitedQuery16* self = new (ELeave) CDelimitedQuery16;
   207 	CleanupStack::PushL(self);
   208 	self->ConstructL(aQuery);
   209 	return self;
   210 	}
   211 
   212 /**
   213 	Destructor.
   214 	
   215 	@since			6.0
   216  */
   217 EXPORT_C CDelimitedQuery16::~CDelimitedQuery16()
   218 	{
   219 	}
   220 	
   221 /**
   222 	Escape encodes segment then inserts the escaped version in a position before the 
   223 	current parsed segment. The new segment should only contain a single query segment, 
   224 	as any query delimiters in the segment will be converted to an escape triple. The 
   225 	parser is left in a state where its current segment is the same one as before the 
   226 	insertion.
   227 						
   228 	@since			6.0
   229 	@param			aSegment	A descriptor with the unescaped query segment.
   230 	@pre 			The query must have been initially parsed.
   231 	@post			The query will have been extended to include the new segment. The 
   232 	current segment will remain as the one before the insertion.
   233  */
   234 EXPORT_C void CDelimitedQuery16::InsertAndEscapeCurrentL(const TDesC16& aSegment)
   235 	{
   236 	// Need to convert to utf8 first
   237 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
   238 	CleanupStack::PushL(utf8);
   239 
   240 	// Create escaped version of component
   241 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   242 	CleanupStack::PushL(escaped);
   243 
   244 	// Convert back to 16-bits
   245 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   246 	converted->Des().Copy(*escaped);
   247 
   248 	// Insert the segment
   249 	InsertCurrentL(*converted);
   250 
   251 	// Cleanup
   252 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   253 	}
   254 
   255 /**
   256 	Escape encodes segment then inserts the escaped version at the back of the query. 
   257 	The new segment should only contain a single query segment, as any query delimiters 
   258 	in the segment will be converted to an escape triple. The parser is left in a state 
   259 	where its current segment is the same one as before the insertion.
   260 						
   261 	@warning		A re-parse is required to ensure that the parser is valid.
   262 	@since			6.0
   263 	@param			aSegment	A descriptor with the unescaped query segment.
   264 	@pre 			The delimiter must have been set. 
   265 	@post			The query will have been extended to include the new segment.
   266 */
   267 EXPORT_C void CDelimitedQuery16::PushAndEscapeBackL(const TDesC16& aSegment)
   268 	{
   269 	// Need to convert to utf8 first
   270 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
   271 	CleanupStack::PushL(utf8);
   272 
   273 	// Create escaped version of component
   274 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   275 	CleanupStack::PushL(escaped);
   276 
   277 	// Convert back to 16-bits
   278 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   279 	converted->Des().Copy(*escaped);
   280 
   281 	// Insert the segment
   282 	PushBackL(*converted);
   283 
   284 	// Cleanup
   285 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   286 	}
   287 
   288 /**
   289 	Escape encodes segment then inserts the escaped version at the front of the query. 
   290 	The new segment should only contain a single query segment, as any query delimiters 
   291 	in the segment will be converted to an escape triple. The parser is left in a state 
   292 	where its current segment is the same one as before the insertion.
   293 						
   294 	@warning		A re-parse is required to ensure that the parser is valid.
   295 	@since			6.0
   296 	@param			aSegment	A descriptor with the unescaped query segment.
   297 	@pre 			The delimiter must have been set. 
   298 	@post			The query will have been extended to include the new segment.
   299  */
   300 EXPORT_C void CDelimitedQuery16::PushAndEscapeFrontL(const TDesC16& aSegment)
   301 	{
   302 	// Need to convert to utf8 first
   303 	HBufC8* utf8 = EscapeUtils::ConvertFromUnicodeToUtf8L(aSegment);
   304 	CleanupStack::PushL(utf8);
   305 
   306 	// Create escaped version of component
   307 	HBufC8* escaped = EscapeUtils::EscapeEncodeL(*utf8, EscapeUtils::EEscapePath);
   308 	CleanupStack::PushL(escaped);
   309 
   310 	// Convert back to 16-bits
   311 	HBufC16* converted = HBufC16::NewLC(escaped->Length());
   312 	converted->Des().Copy(*escaped);
   313 
   314 	// Insert the segment
   315 	PushFrontL(*converted);
   316 
   317 	// Cleanup
   318 	CleanupStack::PopAndDestroy(3, utf8);	// utf8, escaped, converted
   319 	}
   320 
   321 /**
   322 	Constructor. First phase of two-phase construction method. Does non-allocating construction.
   323 						
   324 	@since			6.0
   325  */
   326 CDelimitedQuery16::CDelimitedQuery16()
   327 : CDelimitedDataBase16()
   328 	{
   329 	}
   330 
   331 /**
   332 	Second phase of two-phase construction method. Does any allocations required to fully 
   333 	construct the object.
   334 						
   335 	@since			6.0
   336 	@param			aQuery	A descriptor with the initial query.
   337 	@pre 			First phase of construction is complete.
   338 	@post			The object is fully constructed.
   339  */
   340 void CDelimitedQuery16::ConstructL(const TDesC16& aQuery)
   341 	{
   342 	// Call base class ConstructL()
   343 	CDelimitedDataBase16::ConstructL(aQuery);
   344 
   345 	// Set the delimiter to '&'
   346 	SetDelimiter(TChar('&'));
   347 	}
   348