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