|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CGI parser and generator |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __TNSMLCGISCRIPTPARSER_H__ |
|
20 #define __TNSMLCGISCRIPTPARSER_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <s32strm.h> |
|
25 #include <e32std.h> |
|
26 #include <badesca.h> |
|
27 |
|
28 // CONSTANTS |
|
29 _LIT( KNSmlCGIParserReservedChars, ";/?:@&=+,$[]" ); |
|
30 _LIT( KNSmlCGIParserDateTimeFormat, "%04u%02u%02uT%02u%02u%02uZ" ); |
|
31 _LIT( KNSmlCGIParserDateFormat, "%04u%02u%02u" ); |
|
32 |
|
33 _LIT(KNSmlCGIScriptComparatorEqualToCaseSensitiveStr, "&EQ;"); |
|
34 _LIT(KNSmlCGIScriptComparatorEqualToCaseInSensitiveStr, "&iEQ;"); |
|
35 _LIT(KNSmlCGIScriptComparatorNotEqualToCaseSensitiveStr, "&NE;"); |
|
36 _LIT(KNSmlCGIScriptComparatorNotEqualToCaseInSensitiveStr, "&iNE;"); |
|
37 _LIT(KNSmlCGIScriptComparatorGreaterThanCaseSensitiveStr, ">"); |
|
38 _LIT(KNSmlCGIScriptComparatorGreaterThanCaseInSensitiveStr, "&iGT;"); |
|
39 _LIT(KNSmlCGIScriptComparatorGreaterThanOrEqualToCaseSensitiveStr, "&GE;"); |
|
40 _LIT(KNSmlCGIScriptComparatorGreaterThanOrEqualToCaseInSensitiveStr, "&iGE;"); |
|
41 _LIT(KNSmlCGIScriptComparatorLessThanCaseSensitiveStr, "<"); |
|
42 _LIT(KNSmlCGIScriptComparatorLessThanCaseInSensitiveStr, "&iLT;"); |
|
43 _LIT(KNSmlCGIScriptComparatorLessThanOrEqualCaseSensitiveStr, "&LE;"); |
|
44 _LIT(KNSmlCGIScriptComparatorLessThanOrEqualCaseInSensitiveStr, "&iLE;"); |
|
45 _LIT(KNSmlCGIScriptComparatorContainsValueCaseSensitiveStr, "&CON;"); |
|
46 _LIT(KNSmlCGIScriptComparatorContainsValueCaseInSensitiveStr, "&iCON;"); |
|
47 |
|
48 _LIT(KNSmlCGIScriptLogicalSeparatorAndStr, "&AND;"); |
|
49 _LIT(KNSmlCGIScriptLogicalSeparatorOrStr, "&OR;"); |
|
50 |
|
51 _LIT(KNSmlCGIScriptNullValue, "&NULL;"); |
|
52 _LIT(KNSmlCGIScriptLuidValue, "&LUID;"); |
|
53 |
|
54 _LIT(KNSmlCGIScriptNullStr,""); |
|
55 |
|
56 _LIT(KNSmlCGIScriptBoolTrue, "TRUE"); |
|
57 _LIT(KNSmlCGIScriptBoolFalse, "FALSE"); |
|
58 |
|
59 const TInt KNSmlCGIScriptLogSepCount = 2; |
|
60 const TInt KNSmlCGIParserLogOpsCount = 15; |
|
61 const TInt KNSmlCGIScriptSpecialUsageStringsCount = 2; |
|
62 |
|
63 const TInt KNSmlCGIParserDateTimeLen = 16; |
|
64 const TInt KNSmlCGIParserDateLen = 8; |
|
65 |
|
66 // DATA TYPES |
|
67 // ------------------------------------------------------------------------------------------------ |
|
68 // TNSmlCGIScriptDataType |
|
69 // ------------------------------------------------------------------------------------------------ |
|
70 enum TNSmlCGIScriptDataType |
|
71 { |
|
72 ENSmlCGIScriptDataTypeHBufC, |
|
73 ENSmlCGIScriptDataTypeDate, |
|
74 ENSmlCGIScriptDataTypeDateTime, |
|
75 ENSmlCGIScriptDataTypeNumber, |
|
76 ENSmlCGIScriptDataTypeBoolean, |
|
77 ENSmlCGIScriptDataTypeNoValue, |
|
78 ENSmlCGIScriptDataTypeNull, |
|
79 ENSmlCGIScriptDataTypeUnKnown |
|
80 }; |
|
81 |
|
82 // ------------------------------------------------------------------------------------------------ |
|
83 // TNSmlCGIScriptLogicalOperator |
|
84 // ------------------------------------------------------------------------------------------------ |
|
85 enum TNSmlCGIScriptLogicalOperator |
|
86 { |
|
87 ENSmlCGIScriptLogicalOperatorAnd, |
|
88 ENSmlCGIScriptLogicalOperatorOr, |
|
89 ENSmlCGIScriptLogicalOperatorNull |
|
90 }; |
|
91 |
|
92 // ------------------------------------------------------------------------------------------------ |
|
93 // TNSmlCGIScriptComparator |
|
94 // ------------------------------------------------------------------------------------------------ |
|
95 enum TNSmlCGIScriptComparator |
|
96 { |
|
97 ENSmlCGIScriptComparatorEqualToCaseSensitive, |
|
98 ENSmlCGIScriptComparatorEqualToCaseInSensitive, |
|
99 ENSmlCGIScriptComparatorNotEqualToCaseSensitive, |
|
100 ENSmlCGIScriptComparatorNotEqualToCaseInSensitive, |
|
101 ENSmlCGIScriptComparatorGreaterThanCaseSensitive, |
|
102 ENSmlCGIScriptComparatorGreaterThanCaseInSensitive, |
|
103 ENSmlCGIScriptComparatorGreaterThanOrEqualToCaseSensitive, |
|
104 ENSmlCGIScriptComparatorGreaterThanOrEqualToCaseInSensitive, |
|
105 ENSmlCGIScriptComparatorLessThanCaseSensitive, |
|
106 ENSmlCGIScriptComparatorLessThanCaseInSensitive, |
|
107 ENSmlCGIScriptComparatorLessThanOrEqualCaseSensitive, |
|
108 ENSmlCGIScriptComparatorLessThanOrEqualCaseInSensitive, |
|
109 ENSmlCGIScriptComparatorContainsValueCaseSensitive, |
|
110 ENSmlCGIScriptComparatorContainsValueCaseInSensitive, |
|
111 ENSmlCGIScriptComparatorNull |
|
112 }; |
|
113 |
|
114 // FORWARD DECLARATIONS |
|
115 |
|
116 // CLASS DECLARATION |
|
117 |
|
118 // ------------------------------------------------------------------------------------------------ |
|
119 // TNSmlCGIScriptPart |
|
120 // ------------------------------------------------------------------------------------------------ |
|
121 struct TNSmlCGIScriptPart |
|
122 { |
|
123 HBufC* iName; |
|
124 TAny* iData; |
|
125 TNSmlCGIScriptDataType iDataType; |
|
126 TNSmlCGIScriptComparator iComparator; |
|
127 }; |
|
128 |
|
129 // ------------------------------------------------------------------------------------------------ |
|
130 // TNSmlDataTypesForCGIScriptNames |
|
131 // ------------------------------------------------------------------------------------------------ |
|
132 struct TNSmlDataTypesForCGIScriptNames |
|
133 { |
|
134 HBufC* iKeywordOrProperty; |
|
135 TNSmlCGIScriptDataType iDataType; |
|
136 }; |
|
137 |
|
138 // ------------------------------------------------------------------------------------------------ |
|
139 // CNSmlCGIScript |
|
140 // ------------------------------------------------------------------------------------------------ |
|
141 class CNSmlCGIScript : public CBase |
|
142 { |
|
143 public: |
|
144 /** |
|
145 * CNSmlCGIScript NewL. |
|
146 */ |
|
147 IMPORT_C static CNSmlCGIScript* NewL(); |
|
148 |
|
149 /** |
|
150 * CNSmlCGIScript NewLC. |
|
151 */ |
|
152 IMPORT_C static CNSmlCGIScript* NewLC(); |
|
153 |
|
154 /** |
|
155 * CNSmlCGIScript destructor. |
|
156 * |
|
157 */ |
|
158 ~CNSmlCGIScript(); |
|
159 |
|
160 /** |
|
161 * Returns logical Separator of CNSmlCGIScript. |
|
162 */ |
|
163 IMPORT_C TNSmlCGIScriptLogicalOperator LogicalOperator() const; |
|
164 |
|
165 /** |
|
166 * Sets logical Separator. |
|
167 * @param aSeparator sets logical Separator of CNSmlCGIScript. |
|
168 */ |
|
169 IMPORT_C void SetLogicalOperator( const TNSmlCGIScriptLogicalOperator aSeparator ); |
|
170 |
|
171 /** |
|
172 * Returns script of CNSmlCGIScript. |
|
173 */ |
|
174 IMPORT_C HBufC* CGIScript() const; |
|
175 |
|
176 /** |
|
177 * Sets script of CNSmlCGIScript. |
|
178 * @param aCGIScript sets script of CNSmlCGIScript. |
|
179 */ |
|
180 IMPORT_C void SetCGIScriptL( const TDesC& aCGIScript ); |
|
181 |
|
182 /** |
|
183 * Returns number of records in list. |
|
184 * @return TInt Number of records in list. |
|
185 */ |
|
186 IMPORT_C TInt Count() const; |
|
187 |
|
188 /** |
|
189 * Returns script part at index aIndex from list. |
|
190 * @param aIndex - value between 0 - Count()-1 |
|
191 * @return TNSmlCGIScriptPart pointer to script part at index aIndex. |
|
192 */ |
|
193 IMPORT_C const TNSmlCGIScriptPart* Get( TInt aIndex ) const; |
|
194 |
|
195 /** |
|
196 * Adds new script part to the list. |
|
197 * @param aScriptPart Pointer to script part to add to the list. |
|
198 */ |
|
199 IMPORT_C void AddL( TNSmlCGIScriptPart* aScriptPart ); |
|
200 |
|
201 /** |
|
202 * Removes script part at index aIndex from list. |
|
203 * @param aIndex Index to script part to be removed. |
|
204 * @return TNSmlCGIScriptPart* Pointer to removed script part. |
|
205 */ |
|
206 IMPORT_C TNSmlCGIScriptPart* Remove( TInt aIndex ); |
|
207 |
|
208 /** |
|
209 * Removes all script parts. |
|
210 */ |
|
211 IMPORT_C void Clear(); |
|
212 |
|
213 protected: |
|
214 CNSmlCGIScript(); |
|
215 void ConstructL(); |
|
216 |
|
217 private: |
|
218 TNSmlCGIScriptLogicalOperator iSeparator; |
|
219 HBufC* iCGIScript; |
|
220 CArrayPtrFlat<TNSmlCGIScriptPart>* iScriptParts; |
|
221 TAny* iReserved; |
|
222 }; |
|
223 |
|
224 // ------------------------------------------------------------------------------------------------ |
|
225 // CGI parser/generator |
|
226 // ------------------------------------------------------------------------------------------------ |
|
227 class TNSmlCGIScriptParser |
|
228 { |
|
229 public: |
|
230 // ------------------------------------------------------------------------------------------------ |
|
231 // TNSmlCGIParserError |
|
232 // ------------------------------------------------------------------------------------------------ |
|
233 enum TNSmlCGIParserError |
|
234 { |
|
235 ENSmlCGIParserErrorOk, |
|
236 ENSmlCGIParserErrorDataTypeNotFound, |
|
237 ENSmlCGIParserErrorConversion, |
|
238 ENSmlCGIParserErrorWrongOperator, |
|
239 ENSmlCGIParserErrorWrongSeparator, |
|
240 ENSmlCGIParserErrorParsing, |
|
241 ENSmlCGIParserErrorNoKeyword |
|
242 }; |
|
243 |
|
244 |
|
245 private: |
|
246 // Private helper classes: |
|
247 // ------------------------------------------------------------------------------------------------ |
|
248 // TNSmlCGIScriptParseState |
|
249 // ------------------------------------------------------------------------------------------------ |
|
250 enum TNSmlCGIScriptParseState |
|
251 { |
|
252 ENSmlCGIScriptParseStateKeyWord, |
|
253 ENSmlCGIScriptParseStateLogOp, |
|
254 ENSmlCGIScriptParseStateValue, |
|
255 ENSmlCGIScriptParseStateLogSep |
|
256 }; |
|
257 |
|
258 // ---------------------------------------------------------------------------------------- |
|
259 // TNSmlCGIScriptParseStateInfo |
|
260 // ---------------------------------------------------------------------------------------- |
|
261 struct TNSmlCGIScriptParseStateInfo |
|
262 { |
|
263 TNSmlCGIScriptParseStateInfo( |
|
264 const TDesC* aCGIScript, |
|
265 const CArrayPtr<TNSmlDataTypesForCGIScriptNames>* aDatatypes); |
|
266 TNSmlCGIScriptParseState iState; |
|
267 TNSmlCGIScriptParseState iNextState; |
|
268 const TDesC* iCGIScript; |
|
269 const CArrayPtr<TNSmlDataTypesForCGIScriptNames>* iDatatypes; |
|
270 TInt iStartPos; |
|
271 TInt iCurrPos; |
|
272 }; |
|
273 // ---------------------------------------------------------------------------------------- |
|
274 // TNSmlCGIScriptParseData |
|
275 // ---------------------------------------------------------------------------------------- |
|
276 struct TNSmlCGIScriptParseData |
|
277 { |
|
278 TNSmlCGIScriptParseData(); |
|
279 TPtrC iKeyword; |
|
280 TNSmlCGIScriptDataType iDataType; |
|
281 TPtrC iValue; |
|
282 TNSmlCGIScriptComparator iComparator; |
|
283 TNSmlCGIScriptLogicalOperator iSeparator; |
|
284 TBool iParseDataReady; |
|
285 }; |
|
286 |
|
287 friend struct TNSmlCGIScriptParseStateInfo; |
|
288 |
|
289 public: // Constructors and destructor |
|
290 |
|
291 |
|
292 /** |
|
293 * constructor. |
|
294 */ |
|
295 IMPORT_C TNSmlCGIScriptParser(); |
|
296 |
|
297 public: // New functions |
|
298 |
|
299 /** |
|
300 * Converts cgi-script to a data structure. |
|
301 * @param aSp contains cgi-script (=source) and methods to add parsed data structure (=dest.) there. |
|
302 * @param aDatatypes contains all acceptable keyword and property names and their datatypes. |
|
303 */ |
|
304 IMPORT_C void ParseL(CNSmlCGIScript& aSp, |
|
305 const CArrayPtr<TNSmlDataTypesForCGIScriptNames>& aDatatypes) const; |
|
306 |
|
307 /** |
|
308 * Converts data structure to cgi-script |
|
309 * @param aS contains the data structure (=source) and method to set the generated cgi-script. |
|
310 */ |
|
311 IMPORT_C void GenerateL(CNSmlCGIScript& aS) const; |
|
312 |
|
313 protected: // New functions |
|
314 |
|
315 private: |
|
316 |
|
317 /** |
|
318 * In parsing cgi-script, determines whether to split cgi-script at a certain point or not. |
|
319 * @param aCGIScript - cgi-script |
|
320 * @param aStartFrom - index to cgi-script |
|
321 * @return ETrue if there is split point at aCGIScript[aStartFrom], EFalse otherwise. |
|
322 */ |
|
323 TBool IsParseSplitPoint(const TDesC& aCGIScript, TInt aStartFrom) const; |
|
324 |
|
325 /** |
|
326 * Does the parsing of cgi-script. |
|
327 * @param aPSInfo contains state information needed for parsing (=source) |
|
328 * @param aPD is filled with data, that is parsed (=dest.) |
|
329 * @return EFalse, if ready for handling of next split point, ETrue, if must be called again before next split point. |
|
330 */ |
|
331 TBool ParseStateL(TNSmlCGIScriptParseStateInfo& aPSInfo, TNSmlCGIScriptParseData& aPD) const; |
|
332 |
|
333 /** |
|
334 * adds script part to aSp |
|
335 * @param aSp - script to add script part. (=dest) |
|
336 * @param aPD - parsed data, has the data needed for script part.(=source) |
|
337 * @return ETrue, if script part was added, EFalse otherwise. |
|
338 */ |
|
339 static TBool AddScriptPartL(CNSmlCGIScript& aSp, TNSmlCGIScriptParseData& aPD); |
|
340 |
|
341 /** |
|
342 * parses the script's value. |
|
343 * @param aSp - struct's iData - member receives the parsed value. |
|
344 * @param aValue - value to parse. |
|
345 * @return ETrue, if aSp should be used, EFalse if it should be ignored. |
|
346 */ |
|
347 static TBool ParseScriptPartDataLC(TNSmlCGIScriptPart& aSp, const TPtrC& aValue); |
|
348 |
|
349 /** |
|
350 * finds datatype for a keyword (=script's keyword or propertyname) |
|
351 * @param aDatatypes - array where to search. |
|
352 * @param aKeyword - keyword to search |
|
353 * @return datatype, leaves if not found |
|
354 */ |
|
355 static TNSmlCGIScriptDataType FindDataTypeL(const CArrayPtr<TNSmlDataTypesForCGIScriptNames>& aDatatypes, const TPtrC& aKeyword); |
|
356 |
|
357 /** |
|
358 * similar to FindDataTypeL, but doesn't leave if datatype not found, instead returns TNSmlCGIScriptDataTypeUnKnown. |
|
359 * @param aDatatypes - array where to search. |
|
360 * @param aKeyword - keyword to search |
|
361 * @return datatype, leaves if not found |
|
362 */ |
|
363 static TNSmlCGIScriptDataType FindDataType(const CArrayPtr<TNSmlDataTypesForCGIScriptNames>& aDatatypes, const TPtrC& aKeyword); |
|
364 |
|
365 /** |
|
366 * converts script part to string. |
|
367 * @param aSp - script part to convert |
|
368 * @return converted string. |
|
369 */ |
|
370 HBufC* GenerateScriptPartL(const TNSmlCGIScriptPart& aSp) const; |
|
371 |
|
372 /** |
|
373 * generates the script's value. |
|
374 * @param aDataType - datatype for value. |
|
375 * @param aValue - value to convert. (=source) |
|
376 * @param aPtr receives the generated value (=dest.) |
|
377 */ |
|
378 static void GenerateScriptPartValueL(TNSmlCGIScriptDataType aDataType, const TAny* aValue, TPtr& aPtr); |
|
379 |
|
380 /** |
|
381 * collects script-parts to one cgi-script. |
|
382 * @param aSp - where to set the script (=dest) |
|
383 * @param aBufParts - scripts parts to collect (=source) |
|
384 */ |
|
385 void SetCGIScriptL(CNSmlCGIScript& aSp, CArrayPtr<HBufC>& aBufParts) const; |
|
386 |
|
387 /** |
|
388 * converts cgi-script date to TDateTime. |
|
389 * @param aDateTime receives the parsed datetime(=dest.) |
|
390 * @param aDes - descriptor where date is to be parsed (= source) |
|
391 * @param aStartFrom - index to aDes, where date-string should start. |
|
392 * @return how many letters from aDes[aStartFrom] was needed to get the datetime. |
|
393 */ |
|
394 static TInt ParseDateTimeL(TDateTime& aDateTime, const TDesC& aDes, TInt aStartFrom = 0); |
|
395 |
|
396 /** |
|
397 * converts TDateTime to string-format used by cgi-script. |
|
398 * @param aDateTime - the date to convert(=source.) |
|
399 * @param aDes receives the converted date-string. (=dest.) |
|
400 * @param aUseTimePart is ETrue, if timepart (= hour, minute, second) should be converted too. |
|
401 */ |
|
402 static void GenerateDateTimeValue(const TDateTime& aDateTime, TDes& aDes, TBool aUseTimePart = ETrue); |
|
403 |
|
404 /** |
|
405 * converts boolean value to string-format used by cgi-script. |
|
406 * @param aBool - source boolean value. |
|
407 * @return boolean value as descriptor. |
|
408 */ |
|
409 static const TDesC& GenerateBoolValue(TBool aBool); |
|
410 |
|
411 /** |
|
412 * converts number as descriptor to TInt. |
|
413 * @param aDes - source number. |
|
414 * @param aStartFrom - index to aDes, where the number should be. |
|
415 * @param aLength - how many numbers follows aDes[aStartFrom]. |
|
416 * @return the number as integer. |
|
417 */ |
|
418 static TInt ParseIntL(const TDesC& aDes, TInt aStartFrom, TInt aLength); |
|
419 |
|
420 /** |
|
421 * converts boolean-value as descriptor to TBool |
|
422 * @param aDes - source boolean-value. |
|
423 * @param aStartFrom - index to aDes, where the boolean-value should be. |
|
424 * @return the boolean-value as TBool. |
|
425 */ |
|
426 static TBool ParseBoolL(const TDesC& aDes, TInt aStartFrom = 0); |
|
427 |
|
428 /** |
|
429 * get logical operator as descriptor. |
|
430 * @param aComp - comparator |
|
431 * @return comparator as string. |
|
432 */ |
|
433 const TDesC& LogOpL(TNSmlCGIScriptComparator aComp) const; |
|
434 |
|
435 /** |
|
436 * gets comparator from descriptor. |
|
437 * @param aDes - descriptor, where comparator should be. |
|
438 * @param aInd - index to aDes where comparator should be. aInd should point to next letter following '&'. |
|
439 * @return comparator at aDes[aInd] or else leaves. |
|
440 */ |
|
441 TNSmlCGIScriptComparator LogOpL(const TDesC& aDes, TInt aInd) const; |
|
442 |
|
443 /** |
|
444 * get logical separator as descriptor. |
|
445 * @param aLogSep - separator |
|
446 * @return separator as string. |
|
447 */ |
|
448 const TDesC& LogSepL(TNSmlCGIScriptLogicalOperator aLogSep) const; |
|
449 |
|
450 /** |
|
451 * gets separator from descriptor. |
|
452 * @param aDes - descriptor, where comparator should be. |
|
453 * @param aInd - index to aDes, where comparator should be. aInd should point to next letter following '&'. |
|
454 * @return separator at aDes[aInd] or else leaves. |
|
455 */ |
|
456 TNSmlCGIScriptLogicalOperator LogSepL(const TDesC& aDes, TInt aInd) const; |
|
457 |
|
458 /** |
|
459 * compares comparator to one of equality-operators. |
|
460 * @param aComp - comparator to compare. |
|
461 * @return ETrue, if aComp was one of equality-operators, EFalse otherwise. |
|
462 */ |
|
463 static TBool IsEqualityOperator(TNSmlCGIScriptComparator aComp); |
|
464 |
|
465 /** |
|
466 * checks, if scriptPart-data is valid. Leaves if not. |
|
467 * @param aSp - scriptpart to check. |
|
468 */ |
|
469 static void CheckScriptPartValidityL(const TNSmlCGIScriptPart& aSp); |
|
470 |
|
471 /** |
|
472 * compares descriptors |
|
473 * @param aWhat - what to compare. |
|
474 * @param aWhere - where to compare |
|
475 * @param aStartFrom - index to aWhere. |
|
476 * @return ETrue if aWhat is found exactly at aWhere[aStartFrom], but aWhere can contain letters after the found string. |
|
477 */ |
|
478 static TBool Compare(const TDesC& aWhat, const TDesC& aWhere, TInt aStartFrom); |
|
479 |
|
480 public: // Data |
|
481 |
|
482 protected: // Data |
|
483 |
|
484 private: // Data |
|
485 const TDesC* KNSmlCGIScriptLogSep[KNSmlCGIScriptLogSepCount]; |
|
486 const TDesC* KNSmlCGIScriptLogOps[KNSmlCGIParserLogOpsCount]; |
|
487 const TDesC* KNSmlCGIScriptSpecialUsageStrings[KNSmlCGIScriptSpecialUsageStringsCount]; |
|
488 }; |
|
489 |
|
490 #endif // __TNSMLCGISCRIPTPARSER_H__ |
|
491 |
|
492 |
|
493 // End of File |