1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/mw/http/thttphdrval.h Wed Mar 31 12:27:01 2010 +0100
1.3 @@ -0,0 +1,280 @@
1.4 +// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// 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.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +
1.20 +
1.21 +/**
1.22 + @file THTTPHdrVal.h
1.23 + @warning : This file contains Rose Model ID comments - please do not delete
1.24 +*/
1.25 +
1.26 +#ifndef __THTTPHDRVAL_H__
1.27 +#define __THTTPHDRVAL_H__
1.28 +
1.29 +// System includes
1.30 +#include <e32std.h>
1.31 +#include <stringpool.h>
1.32 +
1.33 +
1.34 +//##ModelId=3C4C187E027A
1.35 +class THTTPHdrVal
1.36 +/**
1.37 +A representation of a value found in an HTTP header field. Three
1.38 +fundamental types are used in HTTP - integers, strings (which may
1.39 +be free text, 'enumeration values', URIs, etc. or date/times.
1.40 +
1.41 +The class allows any of the three values to be held and the current
1.42 +value (as well as its type) to be determined.
1.43 +
1.44 +THTTPHdrVal instances are used to assign values to header fields, their
1.45 +parts and their associated parameters.
1.46 +@publishedAll
1.47 +@released
1.48 +@see RHTTPHeaders
1.49 +*/
1.50 + {
1.51 +public:
1.52 + /**
1.53 + @enum THTTPValType
1.54 + */
1.55 + typedef enum {
1.56 + KTIntVal = 0x00, /**< the value is an integer*/
1.57 + KStrVal = 0x01, /**< the value is a case-sensitive string*/
1.58 + KDateVal = 0x02, /**< the value is a date/time*/
1.59 + KStrFVal = 0x03, /**< the value is a case-insensitive string*/
1.60 + KNoType = 0x04 /**< no value has yet been set*/
1.61 + } THTTPValType;
1.62 +
1.63 +public: // classes
1.64 +
1.65 + // A converter for 'q' parameter values; apparently real numbers in the HTTP RFC but here passed as fixed point
1.66 +//##ModelId=3B1E66F2024E
1.67 + class TQConv
1.68 + {
1.69 + public:
1.70 + /// Construct from a real number representation of 'q'
1.71 + //##ModelId=3B1E66F20282
1.72 + TQConv(TReal aQ);
1.73 +
1.74 + /// Construct from a fixed-point representation of 'q'
1.75 + //##ModelId=3B1E66F2028C
1.76 + TQConv(TInt aQ);
1.77 +
1.78 + /// Integer cast operator to get the fixed-point representation
1.79 + //##ModelId=3B1E66F20281
1.80 + operator TInt() const;
1.81 +
1.82 + /// TReal cast operator to get the real number representation
1.83 + //##ModelId=3B1E66F20280
1.84 + operator TReal() const;
1.85 + private:
1.86 + /// The real number q-value
1.87 + //##ModelId=3B1E66F2027A
1.88 + TReal iQ;
1.89 + /// The integer fixed-point q-value representation
1.90 + //##ModelId=3B1E66F2026E
1.91 + TInt iFQ;
1.92 + };
1.93 +
1.94 +public:
1.95 + /** Default constructor
1.96 + Used when constructing an empty header value that is to be filled in by
1.97 + a call to a function. e.g. RHTTPHeaders::GetField
1.98 + */
1.99 + IMPORT_C THTTPHdrVal();
1.100 +
1.101 + /** Constructor for an integer field value
1.102 + @param aIntVal The integer value
1.103 + */
1.104 + IMPORT_C THTTPHdrVal(TInt aIntVal);
1.105 +
1.106 + /** Constructor for an string value
1.107 + @param aStrVal The string value
1.108 + */
1.109 + IMPORT_C THTTPHdrVal(RStringF aStrVal);
1.110 + /** Constructor for an string value
1.111 + @param aStrVal The string value
1.112 + */
1.113 + IMPORT_C THTTPHdrVal(RString aStrVal);
1.114 +
1.115 + /** Constructor for an date/time value
1.116 + @param aDateVal The date/time value
1.117 + */
1.118 + IMPORT_C THTTPHdrVal(TDateTime aDateVal);
1.119 +
1.120 + /** Obtain a copy of this header value. This is critical when the header contains a string, since
1.121 + a new string reference must be created
1.122 + @return The copied header value
1.123 + */
1.124 + //##ModelId=3C4C187E02F3
1.125 + IMPORT_C THTTPHdrVal Copy() const;
1.126 +
1.127 + /** Determine the type of this header field value
1.128 + @return A THTTPValType enumeration describing the value's type
1.129 + */
1.130 + //##ModelId=3C4C187E02F2
1.131 + IMPORT_C THTTPValType Type() const;
1.132 +
1.133 + /** Obtain the (integer) value held within
1.134 + Panics if the value is of the wring type
1.135 + @pre Requires that the object was previously set to hold a TInt
1.136 + @return An integer value
1.137 + */
1.138 + //##ModelId=3C4C187E02EA
1.139 + IMPORT_C TInt Int() const;
1.140 +
1.141 + /** Cast operator to obtain the HTTP value as an integer.
1.142 + Note this doesn't convert from a different form to integer!
1.143 + Panics if the value is of the wrong type
1.144 + @pre Requires that the object was previously set to hold a TInt
1.145 + */
1.146 + //##ModelId=3C4C187E02E9
1.147 + inline operator TInt() const;
1.148 +
1.149 + /** Obtain the (string) value held within
1.150 + Panics if the value is of the wring type
1.151 + @pre Requires that the object was previously set to hold a string
1.152 + @return A string
1.153 + */
1.154 + //##ModelId=3C4C187E02E8
1.155 + IMPORT_C RStringF StrF() const;
1.156 + //##ModelId=3C4C187E02E0
1.157 + IMPORT_C RString Str() const;
1.158 +
1.159 + /** Cast operator to obtain the HTTP value as a string.
1.160 + Note this doesn't convert from a different form to string!
1.161 + Panics if the value is of the wring type
1.162 + @pre Requires that the object was previously set to hold a string
1.163 + */
1.164 + //##ModelId=3C4C187E02DF
1.165 + inline operator RStringF() const;
1.166 + /** Cast operator to obtain the HTTP value as a string.
1.167 + Note this doesn't convert from a different form to string!
1.168 + Panics if the value is of the wring type
1.169 + @pre Requires that the object was previously set to hold a string
1.170 + */
1.171 + //##ModelId=3C4C187E02DE
1.172 + inline operator RString() const;
1.173 +
1.174 + /** Obtain the (date/time) value held within.
1.175 + Panics if the value is of the wrong type
1.176 + @pre Requires that the object was previously set to hold a TDateTime
1.177 + @return An date/time value
1.178 + */
1.179 + //##ModelId=3C4C187E02D6
1.180 + IMPORT_C TDateTime DateTime() const;
1.181 +
1.182 + /** Cast operator to obtain the HTTP value as an date/time.
1.183 + Note this doesn't convert from a different form to date!
1.184 + Panics if the value is of the wring type
1.185 + @pre Requires that the object was previously set to hold a TDateTime
1.186 + */
1.187 + //##ModelId=3C4C187E02D5
1.188 + inline operator TDateTime() const;
1.189 +
1.190 + /** Set the header value to be the supplied integer.
1.191 + @warning Any previous value, or its type, are lost.
1.192 + @param aIntVal The integer value
1.193 + */
1.194 + //##ModelId=3C4C187E02CC
1.195 + IMPORT_C void SetInt(TInt aIntVal);
1.196 +
1.197 + /** Set the header value to be the supplied string.
1.198 + @warning Any previous value, or its type, are lost.
1.199 + @param aStrVal The string value
1.200 + */
1.201 + //##ModelId=3C4C187E02CA
1.202 + IMPORT_C void SetStrF(RStringF aStrVal);
1.203 + /** Set the header value to be the supplied string. Any previous
1.204 + value, or its type, are lost.
1.205 + @param aStrVal The string value */
1.206 + //##ModelId=3C4C187E02C2
1.207 + IMPORT_C void SetStr(RString aStrVal);
1.208 +
1.209 + /** Set the header value to be the supplied date/time. Any previous value, or its type, are lost.
1.210 + @param aDateVal The date/time value
1.211 + */
1.212 + //##ModelId=3C4C187E02C0
1.213 + IMPORT_C void SetDateTime(TDateTime aDateVal);
1.214 +
1.215 + /** Comparison operator. Does a comparison based on the current type.
1.216 + @param aVal The header value to compare. */
1.217 + //##ModelId=3C4C187E02B8
1.218 + IMPORT_C TBool operator==(THTTPHdrVal aVal) const;
1.219 +
1.220 + /** Comparison operator. Does a comparison based on the current type.
1.221 + @param aVal The string to compare. */
1.222 + //##ModelId=3C4C187E02B6
1.223 + IMPORT_C TBool operator!=(THTTPHdrVal aVal) const;
1.224 +
1.225 +private:
1.226 + /**
1.227 + The current type
1.228 + */
1.229 + //##ModelId=3C4C187E02AC
1.230 + THTTPValType iType;
1.231 +
1.232 + /**
1.233 + The value
1.234 + */
1.235 + //##ModelId=3C4C187E02A4
1.236 + TInt iVal;
1.237 + //##ModelId=3C4C187E029A
1.238 + TInt iMoreSpace;
1.239 + };
1.240 +
1.241 +inline THTTPHdrVal::TQConv::TQConv(TReal aQ)
1.242 + : iQ(aQ), iFQ((TInt)(iQ*1000))
1.243 + {
1.244 + }
1.245 +
1.246 +inline THTTPHdrVal::TQConv::TQConv(TInt aFQ)
1.247 + : iQ((TReal)(aFQ/1000.)), iFQ(aFQ)
1.248 + {
1.249 + }
1.250 +
1.251 +inline THTTPHdrVal::TQConv::operator TInt() const
1.252 + {
1.253 + return iFQ;
1.254 + }
1.255 +
1.256 +inline THTTPHdrVal::TQConv::operator TReal() const
1.257 + {
1.258 + return iQ;
1.259 + }
1.260 +
1.261 +inline THTTPHdrVal::operator TInt() const
1.262 + {
1.263 + return Int();
1.264 + }
1.265 +
1.266 +inline THTTPHdrVal::operator RStringF() const
1.267 + {
1.268 + return StrF();
1.269 + }
1.270 +
1.271 +inline THTTPHdrVal::operator RString() const
1.272 + {
1.273 + return Str();
1.274 + }
1.275 +
1.276 +inline THTTPHdrVal::operator TDateTime() const
1.277 + {
1.278 + return DateTime();
1.279 + }
1.280 +
1.281 +
1.282 +
1.283 +#endif // __THTTPHDRVAL_H__