sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: /**
sl@0:  @file WSPDecoder.h
sl@0:  @publishedAll
sl@0:  @deprecated
sl@0: */
sl@0: 
sl@0: #ifndef	__WSPDECODER_H__
sl@0: #define	__WSPDECODER_H__
sl@0: 
sl@0: #include <e32base.h>
sl@0: #include <stringpool.h>
sl@0: 
sl@0: 
sl@0: /** 
sl@0: * This file contains the following classes:
sl@0: *	TWspField 
sl@0: *	TWspHeaderSegmenter 
sl@0: *	TWspPrimitiveDecoder  
sl@0: *	
sl@0: */
sl@0: 
sl@0: 
sl@0: /**
sl@0: enum DecoderPanic
sl@0: @publishedAll
sl@0: @deprecated
sl@0: */
sl@0: enum TWspDecoderPanic
sl@0: 	{
sl@0: 	/**
sl@0: 	LongIntOverflow
sl@0: 	*/
sl@0: 	EWspDecoderLongIntOverflow,
sl@0: 	/**
sl@0: 	DateOverflow
sl@0: 	*/
sl@0: 	EWspDecoderDateOverflow
sl@0: 	};
sl@0: 
sl@0: /**
sl@0: TWspField class holds the pair <HeaderName, ValueBuffer>
sl@0: This is a simple class that associates these values.
sl@0: No ownership is handed to this class.  It is up to user of this class to
sl@0: open and close all resources used.
sl@0: @publishedAll
sl@0: @deprecated
sl@0: */
sl@0: class TWspField 
sl@0: 	{
sl@0: public:
sl@0: 
sl@0: 	inline TWspField();
sl@0: 
sl@0: 	inline TWspField(RStringF aHdrName, TPtrC8 aValBuf);
sl@0: 
sl@0: 	/**
sl@0: 	The header name of a opened RStringF - *Not Owned*
sl@0: 	This is externally opened.  It must be externally 
sl@0: 	closed.
sl@0: 	*/
sl@0: 	RStringF iHdrName;
sl@0: 	
sl@0: 	/** The raw value buffer - Note: Not owned by this */
sl@0: 	TPtrC8	 iValBuffer;
sl@0: 	};
sl@0: 
sl@0: /** 
sl@0: TWspHeaderSegmenter segments a WSP buffer into WSP header/value pairs.  
sl@0: It detects boundaries between header/values based on the WAP-WSP spec.
sl@0: 	- To construct, buffer and string pool is passed in
sl@0: 	- Call to NextL() to iterate through the buffer - this returns a TWspField
sl@0: 	- NextL() returns KErrNotFound when done
sl@0: 
sl@0: @publishedAll
sl@0: @deprecated
sl@0: */ 
sl@0: class TWspHeaderSegmenter
sl@0: 	{
sl@0: public:
sl@0: 
sl@0: 	inline TWspHeaderSegmenter(RStringPool aPool, const TStringTable& aStringTable, TPtrC8 aBuffer); 
sl@0: 
sl@0: 	IMPORT_C TInt NextL(TWspField& aWspHeader);
sl@0: 
sl@0: 	inline TInt Offset() const;
sl@0: 
sl@0: private:
sl@0: 	/** Raw buffer that will be segmented - Not Owned */
sl@0: 	TPtrC8		iBuffer;
sl@0: 
sl@0: 	/** Segment offset into the buffer. */
sl@0: 	TInt		iOffset;
sl@0: 
sl@0: 	/** Opened string pool to use with the string table already loaded - Not Owned */
sl@0: 	RStringPool iPool;
sl@0: 
sl@0: 	/** The string table to use in the string pool - Not Owned */
sl@0: 	const TStringTable& iStringTable;
sl@0: 	};
sl@0: 
sl@0: /** 
sl@0: Decoder for WSP Primitves - WAP-WSP Section 8.4.1
sl@0: @publishedAll
sl@0: @deprecated
sl@0: */ 
sl@0: class TWspPrimitiveDecoder 
sl@0: 	{
sl@0:   public:
sl@0: 
sl@0: 	/**
sl@0: 	* TWspHeaderType describe the types from WAP-WSP Section 8.4.1.2
sl@0: 	*/
sl@0: 	 enum TWspHeaderType
sl@0: 		{
sl@0: 		/**
sl@0: 		The type has not been set 
sl@0: 		*/
sl@0: 		ENotSet,		
sl@0: 		/**
sl@0: 		0-31 -  octet is a value length 
sl@0: 		*/
sl@0: 		ELengthVal,		
sl@0: 		/**
sl@0: 		34 - value is a quoted text string, terminated by a Null
sl@0: 		*/
sl@0: 		EQuotedString,	
sl@0: 		/** 
sl@0: 		32-127 - value is a text string, terminated by a Null
sl@0: 		*/
sl@0: 		EString,		
sl@0: 		/**
sl@0: 		128-255 - encoded 7 bit value, this header has no more data	
sl@0: 		*/
sl@0: 		E7BitVal		
sl@0: 		};
sl@0: 
sl@0: 			
sl@0: 	inline TWspPrimitiveDecoder(TPtrC8 aBuffer);
sl@0: 	
sl@0: 	IMPORT_C TWspHeaderType VarType() const;
sl@0: 	
sl@0: 	IMPORT_C TInt LengthVal(TInt& aVal);
sl@0: 	
sl@0: 	IMPORT_C TInt String(TPtrC8& aString);
sl@0: 
sl@0: 
sl@0: 	IMPORT_C TInt Val7Bit(TUint8& aVal);
sl@0: 	
sl@0: 	IMPORT_C TInt Integer(TUint32& aVal);
sl@0: 
sl@0: 	IMPORT_C TInt LongInt(TUint32& aVal);
sl@0: 
sl@0: 	IMPORT_C TInt UintVar(TUint32& aVal);
sl@0: 
sl@0: 	IMPORT_C TInt VersionL(RStringPool aPool, RStringF& aVer);
sl@0: 
sl@0: 	IMPORT_C TInt Date(TDateTime& aDateTime);
sl@0:   
sl@0:   private:
sl@0: 	/** The raw buffer */
sl@0: 	TPtrC8 iBuffer;
sl@0: 
sl@0: 	/** The current offset */
sl@0: 	TInt   iOffset;
sl@0: 	};
sl@0: 
sl@0: /**
sl@0:   Constructor
sl@0:   
sl@0:  */
sl@0: inline TWspField::TWspField()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0:   Constructor
sl@0:   
sl@0:   @param aHdrName In - The Header Name.  This must be an opened RStringF
sl@0:   @param aValBuf In - the Buffer containing the header value in its raw format
sl@0: */
sl@0: inline TWspField::TWspField(RStringF aHdrName, TPtrC8 aValBuf) : 
sl@0: 		iHdrName(aHdrName), 
sl@0: 		iValBuffer(aValBuf) 
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0:   Constructor
sl@0: 
sl@0:   @param aPool In - an opened RStringPool - owned by the caller
sl@0:   @param aStringTable In - the string table in the string pool to use
sl@0:   @param aBuffer In - the buffer containing the WSP header data - owned by the caller
sl@0:   @pre The string table must be opened with the WSP Sting constants table
sl@0: */
sl@0: inline TWspHeaderSegmenter::TWspHeaderSegmenter(RStringPool aPool, const TStringTable& aStringTable, TPtrC8 aBuffer) : 
sl@0: 		iBuffer(aBuffer), 
sl@0: 		iOffset(0),
sl@0: 		iPool(aPool),
sl@0: 		iStringTable(aStringTable)
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0:   Offset	returns the current offset into the buffer being parsed.
sl@0:   
sl@0:   @return	TInt offset value. It will point to beginning of next segmented field.
sl@0:  			If NextL has not been called it will be set to 0. The beginning of the buffer.
sl@0:  			If buffer has been completely parsed, will return KErrNotFound.
sl@0: */
sl@0: inline TInt TWspHeaderSegmenter::Offset() const
sl@0: 	{
sl@0: 	return (iOffset < iBuffer.Length()) ? iOffset : KErrNotFound;	
sl@0: 	}
sl@0: 
sl@0: /**
sl@0:   Constructor
sl@0:   
sl@0:   @param aBuffer In - the buffer containing the value in its raw format
sl@0: */
sl@0: inline TWspPrimitiveDecoder::TWspPrimitiveDecoder(TPtrC8 aBuffer) : 
sl@0: 		iBuffer(aBuffer), 
sl@0: 		iOffset(0) 
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: 
sl@0: #endif // __WSPDECODER_H__
sl@0: 
sl@0: