1.1 --- a/epoc32/include/wspdecoder.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/wspdecoder.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,244 @@
1.4 -wspdecoder.h
1.5 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// 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
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +//
1.19 +
1.20 +
1.21 +
1.22 +/**
1.23 + @file WSPDecoder.h
1.24 + @publishedAll
1.25 + @released
1.26 +*/
1.27 +
1.28 +#ifndef __WSPDECODER_H__
1.29 +#define __WSPDECODER_H__
1.30 +
1.31 +#include <e32base.h>
1.32 +#include <stringpool.h>
1.33 +
1.34 +
1.35 +/**
1.36 +* This file contains the following classes:
1.37 +* TWspField
1.38 +* TWspHeaderSegmenter
1.39 +* TWspPrimitiveDecoder
1.40 +*
1.41 +*/
1.42 +
1.43 +
1.44 +/**
1.45 +enum DecoderPanic
1.46 +@publishedAll
1.47 +@released
1.48 +*/
1.49 +enum TWspDecoderPanic
1.50 + {
1.51 + /**
1.52 + LongIntOverflow
1.53 + */
1.54 + EWspDecoderLongIntOverflow,
1.55 + /**
1.56 + DateOverflow
1.57 + */
1.58 + EWspDecoderDateOverflow
1.59 + };
1.60 +
1.61 +/**
1.62 +TWspField class holds the pair <HeaderName, ValueBuffer>
1.63 +This is a simple class that associates these values.
1.64 +No ownership is handed to this class. It is up to user of this class to
1.65 +open and close all resources used.
1.66 +@publishedAll
1.67 +@released
1.68 +*/
1.69 +class TWspField
1.70 + {
1.71 +public:
1.72 +
1.73 + inline TWspField();
1.74 +
1.75 + inline TWspField(RStringF aHdrName, TPtrC8 aValBuf);
1.76 +
1.77 + /**
1.78 + The header name of a opened RStringF - *Not Owned*
1.79 + This is externally opened. It must be externally
1.80 + closed.
1.81 + */
1.82 + RStringF iHdrName;
1.83 +
1.84 + /** The raw value buffer - Note: Not owned by this */
1.85 + TPtrC8 iValBuffer;
1.86 + };
1.87 +
1.88 +/**
1.89 +TWspHeaderSegmenter segments a WSP buffer into WSP header/value pairs.
1.90 +It detects boundaries between header/values based on the WAP-WSP spec.
1.91 + - To construct, buffer and string pool is passed in
1.92 + - Call to NextL() to iterate through the buffer - this returns a TWspField
1.93 + - NextL() returns KErrNotFound when done
1.94 +
1.95 +@publishedAll
1.96 +@released
1.97 +*/
1.98 +class TWspHeaderSegmenter
1.99 + {
1.100 +public:
1.101 +
1.102 + inline TWspHeaderSegmenter(RStringPool aPool, const TStringTable& aStringTable, TPtrC8 aBuffer);
1.103 +
1.104 + IMPORT_C TInt NextL(TWspField& aWspHeader);
1.105 +
1.106 + inline TInt Offset() const;
1.107 +
1.108 +private:
1.109 + /** Raw buffer that will be segmented - Not Owned */
1.110 + TPtrC8 iBuffer;
1.111 +
1.112 + /** Segment offset into the buffer. */
1.113 + TInt iOffset;
1.114 +
1.115 + /** Opened string pool to use with the string table already loaded - Not Owned */
1.116 + RStringPool iPool;
1.117 +
1.118 + /** The string table to use in the string pool - Not Owned */
1.119 + const TStringTable& iStringTable;
1.120 + };
1.121 +
1.122 +/**
1.123 +Decoder for WSP Primitves - WAP-WSP Section 8.4.1
1.124 +@publishedAll
1.125 +@released
1.126 +*/
1.127 +class TWspPrimitiveDecoder
1.128 + {
1.129 + public:
1.130 +
1.131 + /**
1.132 + * TWspHeaderType describe the types from WAP-WSP Section 8.4.1.2
1.133 + */
1.134 + enum TWspHeaderType
1.135 + {
1.136 + /**
1.137 + The type has not been set
1.138 + */
1.139 + ENotSet,
1.140 + /**
1.141 + 0-31 - octet is a value length
1.142 + */
1.143 + ELengthVal,
1.144 + /**
1.145 + 34 - value is a quoted text string, terminated by a Null
1.146 + */
1.147 + EQuotedString,
1.148 + /**
1.149 + 32-127 - value is a text string, terminated by a Null
1.150 + */
1.151 + EString,
1.152 + /**
1.153 + 128-255 - encoded 7 bit value, this header has no more data
1.154 + */
1.155 + E7BitVal
1.156 + };
1.157 +
1.158 +
1.159 + inline TWspPrimitiveDecoder(TPtrC8 aBuffer);
1.160 +
1.161 + IMPORT_C TWspHeaderType VarType() const;
1.162 +
1.163 + IMPORT_C TInt LengthVal(TInt& aVal);
1.164 +
1.165 + IMPORT_C TInt String(TPtrC8& aString);
1.166 +
1.167 +
1.168 + IMPORT_C TInt Val7Bit(TUint8& aVal);
1.169 +
1.170 + IMPORT_C TInt Integer(TUint32& aVal);
1.171 +
1.172 + IMPORT_C TInt LongInt(TUint32& aVal);
1.173 +
1.174 + IMPORT_C TInt UintVar(TUint32& aVal);
1.175 +
1.176 + IMPORT_C TInt VersionL(RStringPool aPool, RStringF& aVer);
1.177 +
1.178 + IMPORT_C TInt Date(TDateTime& aDateTime);
1.179 +
1.180 + private:
1.181 + /** The raw buffer */
1.182 + TPtrC8 iBuffer;
1.183 +
1.184 + /** The current offset */
1.185 + TInt iOffset;
1.186 + };
1.187 +
1.188 +/**
1.189 + Constructor
1.190 +
1.191 + */
1.192 +inline TWspField::TWspField()
1.193 + {
1.194 + }
1.195 +
1.196 +/**
1.197 + Constructor
1.198 +
1.199 + @param aHdrName In - The Header Name. This must be an opened RStringF
1.200 + @param aValBuf In - the Buffer containing the header value in its raw format
1.201 +*/
1.202 +inline TWspField::TWspField(RStringF aHdrName, TPtrC8 aValBuf) :
1.203 + iHdrName(aHdrName),
1.204 + iValBuffer(aValBuf)
1.205 + {
1.206 + }
1.207 +
1.208 +/**
1.209 + Constructor
1.210 +
1.211 + @param aPool In - an opened RStringPool - owned by the caller
1.212 + @param aStringTable In - the string table in the string pool to use
1.213 + @param aBuffer In - the buffer containing the WSP header data - owned by the caller
1.214 + @pre The string table must be opened with the WSP Sting constants table
1.215 +*/
1.216 +inline TWspHeaderSegmenter::TWspHeaderSegmenter(RStringPool aPool, const TStringTable& aStringTable, TPtrC8 aBuffer) :
1.217 + iBuffer(aBuffer),
1.218 + iOffset(0),
1.219 + iPool(aPool),
1.220 + iStringTable(aStringTable)
1.221 + {
1.222 + }
1.223 +
1.224 +/**
1.225 + Offset returns the current offset into the buffer being parsed.
1.226 +
1.227 + @return TInt offset value. It will point to beginning of next segmented field.
1.228 + If NextL has not been called it will be set to 0. The beginning of the buffer.
1.229 + If buffer has been completely parsed, will return KErrNotFound.
1.230 +*/
1.231 +inline TInt TWspHeaderSegmenter::Offset() const
1.232 + {
1.233 + return (iOffset < iBuffer.Length()) ? iOffset : KErrNotFound;
1.234 + }
1.235 +
1.236 +/**
1.237 + Constructor
1.238 +
1.239 + @param aBuffer In - the buffer containing the value in its raw format
1.240 +*/
1.241 +inline TWspPrimitiveDecoder::TWspPrimitiveDecoder(TPtrC8 aBuffer) :
1.242 + iBuffer(aBuffer),
1.243 + iOffset(0)
1.244 + {
1.245 + }
1.246 +
1.247 +
1.248 +#endif // __WSPDECODER_H__