epoc32/include/wspdecoder.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 wspdecoder.h
     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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 /**
       
    19  @file WSPDecoder.h
       
    20  @publishedAll
       
    21  @released
       
    22 */
       
    23 
       
    24 #ifndef	__WSPDECODER_H__
       
    25 #define	__WSPDECODER_H__
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <stringpool.h>
       
    29 
       
    30 
       
    31 /** 
       
    32 * This file contains the following classes:
       
    33 *	TWspField 
       
    34 *	TWspHeaderSegmenter 
       
    35 *	TWspPrimitiveDecoder  
       
    36 *	
       
    37 */
       
    38 
       
    39 
       
    40 /**
       
    41 enum DecoderPanic
       
    42 @publishedAll
       
    43 @released
       
    44 */
       
    45 enum TWspDecoderPanic
       
    46 	{
       
    47 	/**
       
    48 	LongIntOverflow
       
    49 	*/
       
    50 	EWspDecoderLongIntOverflow,
       
    51 	/**
       
    52 	DateOverflow
       
    53 	*/
       
    54 	EWspDecoderDateOverflow
       
    55 	};
       
    56 
       
    57 /**
       
    58 TWspField class holds the pair <HeaderName, ValueBuffer>
       
    59 This is a simple class that associates these values.
       
    60 No ownership is handed to this class.  It is up to user of this class to
       
    61 open and close all resources used.
       
    62 @publishedAll
       
    63 @released
       
    64 */
       
    65 class TWspField 
       
    66 	{
       
    67 public:
       
    68 
       
    69 	inline TWspField();
       
    70 
       
    71 	inline TWspField(RStringF aHdrName, TPtrC8 aValBuf);
       
    72 
       
    73 	/**
       
    74 	The header name of a opened RStringF - *Not Owned*
       
    75 	This is externally opened.  It must be externally 
       
    76 	closed.
       
    77 	*/
       
    78 	RStringF iHdrName;
       
    79 	
       
    80 	/** The raw value buffer - Note: Not owned by this */
       
    81 	TPtrC8	 iValBuffer;
       
    82 	};
       
    83 
       
    84 /** 
       
    85 TWspHeaderSegmenter segments a WSP buffer into WSP header/value pairs.  
       
    86 It detects boundaries between header/values based on the WAP-WSP spec.
       
    87 	- To construct, buffer and string pool is passed in
       
    88 	- Call to NextL() to iterate through the buffer - this returns a TWspField
       
    89 	- NextL() returns KErrNotFound when done
       
    90 
       
    91 @publishedAll
       
    92 @released
       
    93 */ 
       
    94 class TWspHeaderSegmenter
       
    95 	{
       
    96 public:
       
    97 
       
    98 	inline TWspHeaderSegmenter(RStringPool aPool, const TStringTable& aStringTable, TPtrC8 aBuffer); 
       
    99 
       
   100 	IMPORT_C TInt NextL(TWspField& aWspHeader);
       
   101 
       
   102 	inline TInt Offset() const;
       
   103 
       
   104 private:
       
   105 	/** Raw buffer that will be segmented - Not Owned */
       
   106 	TPtrC8		iBuffer;
       
   107 
       
   108 	/** Segment offset into the buffer. */
       
   109 	TInt		iOffset;
       
   110 
       
   111 	/** Opened string pool to use with the string table already loaded - Not Owned */
       
   112 	RStringPool iPool;
       
   113 
       
   114 	/** The string table to use in the string pool - Not Owned */
       
   115 	const TStringTable& iStringTable;
       
   116 	};
       
   117 
       
   118 /** 
       
   119 Decoder for WSP Primitves - WAP-WSP Section 8.4.1
       
   120 @publishedAll
       
   121 @released
       
   122 */ 
       
   123 class TWspPrimitiveDecoder 
       
   124 	{
       
   125   public:
       
   126 
       
   127 	/**
       
   128 	* TWspHeaderType describe the types from WAP-WSP Section 8.4.1.2
       
   129 	*/
       
   130 	 enum TWspHeaderType
       
   131 		{
       
   132 		/**
       
   133 		The type has not been set 
       
   134 		*/
       
   135 		ENotSet,		
       
   136 		/**
       
   137 		0-31 -  octet is a value length 
       
   138 		*/
       
   139 		ELengthVal,		
       
   140 		/**
       
   141 		34 - value is a quoted text string, terminated by a Null
       
   142 		*/
       
   143 		EQuotedString,	
       
   144 		/** 
       
   145 		32-127 - value is a text string, terminated by a Null
       
   146 		*/
       
   147 		EString,		
       
   148 		/**
       
   149 		128-255 - encoded 7 bit value, this header has no more data	
       
   150 		*/
       
   151 		E7BitVal		
       
   152 		};
       
   153 
       
   154 			
       
   155 	inline TWspPrimitiveDecoder(TPtrC8 aBuffer);
       
   156 	
       
   157 	IMPORT_C TWspHeaderType VarType() const;
       
   158 	
       
   159 	IMPORT_C TInt LengthVal(TInt& aVal);
       
   160 	
       
   161 	IMPORT_C TInt String(TPtrC8& aString);
       
   162 
       
   163 
       
   164 	IMPORT_C TInt Val7Bit(TUint8& aVal);
       
   165 	
       
   166 	IMPORT_C TInt Integer(TUint32& aVal);
       
   167 
       
   168 	IMPORT_C TInt LongInt(TUint32& aVal);
       
   169 
       
   170 	IMPORT_C TInt UintVar(TUint32& aVal);
       
   171 
       
   172 	IMPORT_C TInt VersionL(RStringPool aPool, RStringF& aVer);
       
   173 
       
   174 	IMPORT_C TInt Date(TDateTime& aDateTime);
       
   175   
       
   176   private:
       
   177 	/** The raw buffer */
       
   178 	TPtrC8 iBuffer;
       
   179 
       
   180 	/** The current offset */
       
   181 	TInt   iOffset;
       
   182 	};
       
   183 
       
   184 /**
       
   185   Constructor
       
   186   
       
   187  */
       
   188 inline TWspField::TWspField()
       
   189 	{
       
   190 	}
       
   191 
       
   192 /**
       
   193   Constructor
       
   194   
       
   195   @param aHdrName In - The Header Name.  This must be an opened RStringF
       
   196   @param aValBuf In - the Buffer containing the header value in its raw format
       
   197 */
       
   198 inline TWspField::TWspField(RStringF aHdrName, TPtrC8 aValBuf) : 
       
   199 		iHdrName(aHdrName), 
       
   200 		iValBuffer(aValBuf) 
       
   201 	{
       
   202 	}
       
   203 
       
   204 /**
       
   205   Constructor
       
   206 
       
   207   @param aPool In - an opened RStringPool - owned by the caller
       
   208   @param aStringTable In - the string table in the string pool to use
       
   209   @param aBuffer In - the buffer containing the WSP header data - owned by the caller
       
   210   @pre The string table must be opened with the WSP Sting constants table
       
   211 */
       
   212 inline TWspHeaderSegmenter::TWspHeaderSegmenter(RStringPool aPool, const TStringTable& aStringTable, TPtrC8 aBuffer) : 
       
   213 		iBuffer(aBuffer), 
       
   214 		iOffset(0),
       
   215 		iPool(aPool),
       
   216 		iStringTable(aStringTable)
       
   217 	{
       
   218 	}
       
   219 
       
   220 /**
       
   221   Offset	returns the current offset into the buffer being parsed.
       
   222   
       
   223   @return	TInt offset value. It will point to beginning of next segmented field.
       
   224  			If NextL has not been called it will be set to 0. The beginning of the buffer.
       
   225  			If buffer has been completely parsed, will return KErrNotFound.
       
   226 */
       
   227 inline TInt TWspHeaderSegmenter::Offset() const
       
   228 	{
       
   229 	return (iOffset < iBuffer.Length()) ? iOffset : KErrNotFound;	
       
   230 	}
       
   231 
       
   232 /**
       
   233   Constructor
       
   234   
       
   235   @param aBuffer In - the buffer containing the value in its raw format
       
   236 */
       
   237 inline TWspPrimitiveDecoder::TWspPrimitiveDecoder(TPtrC8 aBuffer) : 
       
   238 		iBuffer(aBuffer), 
       
   239 		iOffset(0) 
       
   240 	{
       
   241 	}
       
   242 
       
   243 
       
   244 #endif // __WSPDECODER_H__