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