epoc32/include/chttpresponse.h
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/chttpresponse.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,363 @@
     1.4 +// Copyright (c) 1998-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 +// Purpose:  This file provides the definition of the CHTTPResponse class.
    1.18 +// The HTTP Response class encodes HTTP response headers only. It
    1.19 +// contains the methods used to transcode from WSP->HTTP fields
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#ifndef __CHTTPRESPONSE_H__
    1.24 +#define __CHTTPRESPONSE_H__
    1.25 +
    1.26 +// System includes
    1.27 +//
    1.28 +#include <e32base.h>
    1.29 +#include <logdef.h>
    1.30 +#include <httpstd.h>
    1.31 +#include <thttpfields.h>
    1.32 +
    1.33 +
    1.34 +// Forward class declarations
    1.35 +//
    1.36 +class CPushMessage;
    1.37 +
    1.38 +// Class definition for CHTTPResponse
    1.39 +//
    1.40 +//##ModelId=3B712B9A0231
    1.41 +class CHTTPResponse : public CBase
    1.42 +/**
    1.43 +@publishedAll
    1.44 +@deprecated
    1.45 +*/
    1.46 +    {
    1.47 +public:	// Methods
    1.48 +
    1.49 +	// Factory method to construct this class.
    1.50 +	//
    1.51 +	// Rtn: a new CHTTPResponse object, by ptr. Ownership is transferred to the
    1.52 +	//      caller.
    1.53 +	//
    1.54 +	//##ModelId=3B712B9B000A
    1.55 +	IMPORT_C static CHTTPResponse* NewL();
    1.56 +
    1.57 +	// Destructor for this class. Removes this object and releases memory held
    1.58 +	// by it
    1.59 +	//
    1.60 +	//##ModelId=3B712B9B0000
    1.61 +	IMPORT_C virtual ~CHTTPResponse();
    1.62 +
    1.63 +	// Clean out the fields buffer
    1.64 +	//
    1.65 +	//##ModelId=3B712B9A03D6
    1.66 +	IMPORT_C void Reset();
    1.67 +
    1.68 +	// Set the fields buffer with the response received from the WAP Stack
    1.69 +	//
    1.70 +	// In:
    1.71 +	//  aResponse - an 8-bit descriptor field containing the origin server's
    1.72 +	//				WSP-encoded response header. Ownership is transferred to
    1.73 +	//				this class.
    1.74 +	//
    1.75 +	//##ModelId=3B712B9A03D4
    1.76 +	IMPORT_C void AddResponse(HBufC8* aResponse);
    1.77 +
    1.78 +	// Accessor to the HTTP response fields buffer
    1.79 +	//
    1.80 +	// Rtn: a reference to the response. Ownership is _NOT_ transferred
    1.81 +	//
    1.82 +	// NOTE THIS SHOULD RETURN CONST - BUT CAN'T BE CHANGED SINCE IT WOULD
    1.83 +	// BREAK BC.
    1.84 +	//##ModelId=3B712B9A03CA
    1.85 +	IMPORT_C HBufC8& Response() const;
    1.86 +
    1.87 + 	// Accessor to the HTTP status code (e.g. 400, 300, 200, 500)
    1.88 +	//
    1.89 +	// Rtn: the status code - series number only.
    1.90 +	//
    1.91 +	//##ModelId=3B712B9A03C1
    1.92 +	IMPORT_C THttpStatusCode StatusCode() const;
    1.93 +
    1.94 + 	// Accessor to the HTTP detailed status code (e.g. 404, 304, 200, 501)
    1.95 +	//
    1.96 +	// Rtn: the status code - series and specific code value
    1.97 +	//
    1.98 +	//##ModelId=3B712B9A03C0
    1.99 +	IMPORT_C THttpStatusCode DetailedStatusCode() const;
   1.100 +
   1.101 +	// Accessor to set the HTTP response status.
   1.102 +	//
   1.103 +	// In:
   1.104 +	//  aCode - the WSP-encoded status code
   1.105 +	//
   1.106 +	//##ModelId=3B712B9A03B6
   1.107 +	IMPORT_C void SetStatusCode(TInt aCode);
   1.108 +
   1.109 +	// Method to find a named field, that returns null terminated 
   1.110 +	// WSP text strings.
   1.111 +	//
   1.112 +	// In:
   1.113 +	//  aField		- the field type
   1.114 +	//  aStartIndex	- the index to search from (defaults to the buffer start)
   1.115 +	//
   1.116 +	// Out:
   1.117 +	//  aDesc - a pointer-type descriptor into the response buffer at the
   1.118 +	//			position where the field was located. The caller must NOT
   1.119 +	//			modify the descriptor contents
   1.120 +	//
   1.121 +	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
   1.122 +	//
   1.123 +	//##ModelId=3B712B9A0390
   1.124 +	IMPORT_C TBool FindField(THttpHeaderField aField
   1.125 +                             , TPtrC8& aDesc
   1.126 +                             , TInt aStartIndex = 0) const;
   1.127 +
   1.128 +	// Method to find a named field, that returns 8-bit octet data (binary
   1.129 +	// or strings - not stipulated which).
   1.130 +	//
   1.131 +	// In:
   1.132 +	//  aField		- the field type
   1.133 +	//  aStartIndex	- the index to search from (defaults to the buffer start)
   1.134 +	//
   1.135 +	// Out:
   1.136 +	//  aDesc - a pointer-type descriptor into the response buffer at the
   1.137 +	//			position where the field was located. The caller must NOT
   1.138 +	//			modify the descriptor contents
   1.139 +	//
   1.140 +	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
   1.141 +	//
   1.142 +	//##ModelId=3B712B9A0384
   1.143 +	IMPORT_C TBool FindBinaryDescField(THttpHeaderField aField 
   1.144 +							, TPtrC8& aDesc
   1.145 +							, TInt aStartIndex = 0) const;
   1.146 +
   1.147 +	// Method to find a named field, that returns an EPOC date/time structure.
   1.148 +	//
   1.149 +	// In:
   1.150 +	//  aField		- the field type
   1.151 +	//  aStartIndex	- the index to search from (defaults to the buffer start)
   1.152 +	//
   1.153 +	// Out:
   1.154 +	//  aTime - a structure containing the time (and date) found in the header
   1.155 +	//
   1.156 +	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
   1.157 +	//
   1.158 +	//##ModelId=3B712B9A03A2
   1.159 +	IMPORT_C TBool FindField(THttpHeaderField aField
   1.160 +                             , TTime& aTime
   1.161 +                             , TInt aStartIndex = 0) const;
   1.162 +
   1.163 +	// Method to find a named field within the Cache Control header
   1.164 +	//
   1.165 +	// In:
   1.166 +	//  aField		- the field type
   1.167 +	//
   1.168 +	// Out:
   1.169 +	//
   1.170 +	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
   1.171 +	//
   1.172 +	//##ModelId=3B712B9A0370
   1.173 +	IMPORT_C TInt FindCacheControlFieldValue(TCacheControlFieldValue aField) const;
   1.174 +
   1.175 +	// Method to find a named field within the Cache Control header, 
   1.176 +	// that returns an EPOC date/time structure.
   1.177 +	//
   1.178 +	// In:
   1.179 +	//  aField		- the field type
   1.180 +	//
   1.181 +	// Out:
   1.182 +	//  aTime - a structure containing the time (and date) found in the header field
   1.183 +	//
   1.184 +	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
   1.185 +	//
   1.186 +	//##ModelId=3B712B9A035C
   1.187 +	IMPORT_C TBool ExtractCacheControlTime(TCacheControlFieldValue aField, TTime& aTime) const;
   1.188 +
   1.189 +	// Method to search for the content type encoded in the response header
   1.190 +	//
   1.191 +	// Out:
   1.192 +	//  aDesc - a pointer-type descriptor into the appropriate element of an
   1.193 +	//			array prefilled with all the content types that have WSP
   1.194 +	//			encodings. e.g. "text/vnd.wap.wml".  The contents of the
   1.195 +	//			descriptor must NOT be modified.
   1.196 +	//
   1.197 +	//##ModelId=3B712B9A0348
   1.198 +	IMPORT_C void ContentType(TPtrC8& aDesc) const;
   1.199 +
   1.200 +	// Method to search for the realm encoded in the response header, when the
   1.201 +	// response challenges the client for HTTP authentication (code 401)
   1.202 +	//
   1.203 +	// Out:
   1.204 +	//  aDesc - a pointer-type descriptor into the response header buffer
   1.205 +	//			positioned at the realm string within the challenge. The
   1.206 +	//			contents of the descriptor must NOT be modified.
   1.207 +	//
   1.208 +	// Rtn: TBool - set to ETrue if a www-authenticate realm was found, EFalse
   1.209 +	//				otherwise
   1.210 +	//
   1.211 +	//##ModelId=3B712B9A033F
   1.212 +	IMPORT_C TBool FindRealm(TPtrC8& aRealm) const;
   1.213 +
   1.214 +	// Method to search for the character set encoded in the Content-Type
   1.215 +	// field ofthe response header
   1.216 +	//
   1.217 +	// Out:
   1.218 +	//  aDesc - a pointer-type descriptor into the appropriate element of an
   1.219 +	//			array prefilled with all the character sets that have WSP
   1.220 +	//			encodings. e.g. "utf-8".  The contents of the descriptor must
   1.221 +	//			NOT be modified.
   1.222 +	//
   1.223 +	// Rtn: TBool - set to ETrue if a character set was found, EFalse if not
   1.224 +	//
   1.225 +	//##ModelId=3B712B9A032A
   1.226 +	IMPORT_C TBool CharSet(TPtrC8& aDesc) const;
   1.227 +
   1.228 +protected: // Methods
   1.229 +
   1.230 +	// Normal constructor - do non-allocating creation of this class
   1.231 +	//
   1.232 +    IMPORT_C CHTTPResponse();
   1.233 +
   1.234 +	// Second phase construction - any allocation for this class must take place
   1.235 +	// here. Sets up the resources required by an HTTP Response.
   1.236 +	//
   1.237 +	//##ModelId=3B712B9A0322
   1.238 +	IMPORT_C void ConstructL();
   1.239 +
   1.240 +	//friend class declaration - only need the following function
   1.241 +	friend class CPushMessage;
   1.242 +	// Method to locate a named field in the response header, starting at the
   1.243 +	// specified index position.
   1.244 +	//
   1.245 +	// In:
   1.246 +	//  aField		- the header field type
   1.247 +	//  aStartIndex - the (optional) position in the header to start searching
   1.248 +	//
   1.249 +	// Rtn: TInt - the index position of the required field _value_ (not the
   1.250 +	//             field name), or KErrNotFound otherwise.
   1.251 +	//
   1.252 +	//##ModelId=3B712B9A030D
   1.253 +	IMPORT_C TInt LocateField(THttpHeaderField aField, TInt aStartIndex = 0) const; 
   1.254 +
   1.255 +	// Perform a look-up of content type given a WSP encoding value, used as
   1.256 +	// an index.
   1.257 +	//
   1.258 +	// In:
   1.259 +	//  aIndex - the WSP encoding value
   1.260 +	//
   1.261 +	// Rtn: const TText8* - the required content type text - NOT to be changed
   1.262 +	//
   1.263 +	//##ModelId=3B712B9A0352
   1.264 +	IMPORT_C const TText8* ContentType(TInt aContentTypeCode) const;
   1.265 +
   1.266 + 	// Perform a look-up of character set given a WSP encoding value, used as
   1.267 +	// an index.
   1.268 +	//
   1.269 +	// In:
   1.270 +	//  aCharsetCode - the index into the content types table/
   1.271 +	//
   1.272 +	// Rtn: const TText8* - the required 8-bit character set text - NOT to be
   1.273 +	//						changed by the caller
   1.274 +	//
   1.275 +	//##ModelId=3B712B9A0334
   1.276 +	IMPORT_C const TText8* CharSet(TInt aCharsetCode) const;
   1.277 +
   1.278 +private: // Attributes
   1.279 +
   1.280 +	// The 8-bit buffer used to store the HTTP response fields
   1.281 +	//
   1.282 +	//##ModelId=3B712B9A02AA
   1.283 +    HBufC8* iResponse;
   1.284 +
   1.285 +	// The HTTP Status code (coarse - ie. series only, e.g. 100, 200 etc.)
   1.286 +	//
   1.287 +	//##ModelId=3B712B9A0296
   1.288 +    THttpStatusCode iStatusCode;
   1.289 +
   1.290 +	// The detailed HTTP Status code (within series, e.g. 102, 204, 401 etc.)
   1.291 +	//
   1.292 +	//##ModelId=3B712B9A0282
   1.293 +    THttpStatusCode iDetailedStatusCode;
   1.294 +
   1.295 +	// Declare the CLogClient pointer
   1.296 +   	__DECLARE_LOG
   1.297 +
   1.298 +private: // Methods
   1.299 +
   1.300 +	// Do a conversion from 32-bit UIntVar encoding into 32-bit integer
   1.301 +	//
   1.302 +	TInt ParseUIntVar(const TDesC8& aBuffer, TInt& aVal) const;
   1.303 +
   1.304 +	// Extract a WSP encoded MultiOctet Integer encoding into 32-bit integer
   1.305 +	//
   1.306 +	// In:
   1.307 +	//  aSource	- the source Multi-Octet integer
   1.308 +	//
   1.309 +	// Out:
   1.310 +	//  aInt		- the 32-bit resulting integer
   1.311 +	//
   1.312 +	//##ModelId=3B712B9A02F8
   1.313 +	void ExtractMultiOctetInteger(TInt& aInt, const TPtrC8& aSource) const;
   1.314 +
   1.315 +	// Method to find a named field within the Cache Control header
   1.316 +	//
   1.317 +	// In:
   1.318 +	//  aSource		- the descriptor containing the date value
   1.319 +	//	aFrom		- The position in the descriptor to start from
   1.320 +	//
   1.321 +	// Out:
   1.322 +	//  aTime - a structure containing the time (and date) found in the descriptor
   1.323 +	//
   1.324 +	//##ModelId=3B712B9A02E4
   1.325 +	void ExtractFieldDateValue(const TPtrC8& aSource, TInt aFrom, TTime& aTime) const;
   1.326 +
   1.327 +	// Method to find a named field within the Cache Control header
   1.328 +	//
   1.329 +	// In:
   1.330 +	//  aField		- the field type
   1.331 +	//
   1.332 +	// Out:
   1.333 +	//	the found aCacheControl string
   1.334 +	//
   1.335 +	// Rtn: TInt - set to KErrNotFound if the field was not found,
   1.336 +	//		otherwise the position in the cache control descriptor that the field was found
   1.337 +	//
   1.338 +	//##ModelId=3B712B9A0372
   1.339 +	TInt FindCacheControlFieldValue(TCacheControlFieldValue aField,TPtrC8& aCacheControl) const;
   1.340 +
   1.341 +	//##ModelId=3B712B9A02DA
   1.342 +    void Panic(THttpPanicCode aPanicCode) const;
   1.343 +
   1.344 +	// Spare methods for future BC. Const- and non-const versions to assist
   1.345 +	// the caller in preserving const-ness. IMPORT_C ensures they reserve a
   1.346 +	// slot in the vtbl, which is essential to preseve future BC.
   1.347 +	//
   1.348 +	//##ModelId=3B712B9A02D0
   1.349 +	IMPORT_C virtual TAny* Extend_CHTTPResponse(TAny* aArgs);
   1.350 +	//##ModelId=3B712B9A02C6
   1.351 +	IMPORT_C virtual TAny* Extend_CHTTPResponse_const(TAny* aArgs) const;
   1.352 +
   1.353 +#if defined _DEBUG
   1.354 +	// Debug method definition to allow class invariant testing
   1.355 +	// Called by the standard macro __TEST_INVARIANT
   1.356 +	//
   1.357 +	//##ModelId=3B712B9A02BD
   1.358 +	void __DbgTestInvariant() const;
   1.359 +
   1.360 +	//##ModelId=3B712B9A02B2
   1.361 +	void DumpToLog(const TDesC8& aData) const;
   1.362 +#endif
   1.363 +
   1.364 +	};
   1.365 +
   1.366 +#endif // __CHTTPRESPONSE_H__