epoc32/include/mw/chttpresponse.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/chttpresponse.h@2fe1408b6811
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) 1998-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
// Purpose:  This file provides the definition of the CHTTPResponse class.
williamr@2
    15
// The HTTP Response class encodes HTTP response headers only. It
williamr@2
    16
// contains the methods used to transcode from WSP->HTTP fields
williamr@2
    17
// 
williamr@2
    18
//
williamr@2
    19
williamr@2
    20
#ifndef __CHTTPRESPONSE_H__
williamr@2
    21
#define __CHTTPRESPONSE_H__
williamr@2
    22
williamr@2
    23
// System includes
williamr@2
    24
//
williamr@2
    25
#include <e32base.h>
williamr@2
    26
#include <logdef.h>
williamr@2
    27
#include <httpstd.h>
williamr@2
    28
#include <thttpfields.h>
williamr@2
    29
williamr@2
    30
williamr@2
    31
// Forward class declarations
williamr@2
    32
//
williamr@2
    33
class CPushMessage;
williamr@2
    34
williamr@2
    35
// Class definition for CHTTPResponse
williamr@2
    36
//
williamr@2
    37
//##ModelId=3B712B9A0231
williamr@2
    38
class CHTTPResponse : public CBase
williamr@2
    39
/**
williamr@2
    40
@publishedAll
williamr@2
    41
@deprecated
williamr@2
    42
*/
williamr@2
    43
    {
williamr@2
    44
public:	// Methods
williamr@2
    45
williamr@2
    46
	// Factory method to construct this class.
williamr@2
    47
	//
williamr@2
    48
	// Rtn: a new CHTTPResponse object, by ptr. Ownership is transferred to the
williamr@2
    49
	//      caller.
williamr@2
    50
	//
williamr@2
    51
	//##ModelId=3B712B9B000A
williamr@2
    52
	IMPORT_C static CHTTPResponse* NewL();
williamr@2
    53
williamr@2
    54
	// Destructor for this class. Removes this object and releases memory held
williamr@2
    55
	// by it
williamr@2
    56
	//
williamr@2
    57
	//##ModelId=3B712B9B0000
williamr@2
    58
	IMPORT_C virtual ~CHTTPResponse();
williamr@2
    59
williamr@2
    60
	// Clean out the fields buffer
williamr@2
    61
	//
williamr@2
    62
	//##ModelId=3B712B9A03D6
williamr@2
    63
	IMPORT_C void Reset();
williamr@2
    64
williamr@2
    65
	// Set the fields buffer with the response received from the WAP Stack
williamr@2
    66
	//
williamr@2
    67
	// In:
williamr@2
    68
	//  aResponse - an 8-bit descriptor field containing the origin server's
williamr@2
    69
	//				WSP-encoded response header. Ownership is transferred to
williamr@2
    70
	//				this class.
williamr@2
    71
	//
williamr@2
    72
	//##ModelId=3B712B9A03D4
williamr@2
    73
	IMPORT_C void AddResponse(HBufC8* aResponse);
williamr@2
    74
williamr@2
    75
	// Accessor to the HTTP response fields buffer
williamr@2
    76
	//
williamr@2
    77
	// Rtn: a reference to the response. Ownership is _NOT_ transferred
williamr@2
    78
	//
williamr@2
    79
	// NOTE THIS SHOULD RETURN CONST - BUT CAN'T BE CHANGED SINCE IT WOULD
williamr@2
    80
	// BREAK BC.
williamr@2
    81
	//##ModelId=3B712B9A03CA
williamr@2
    82
	IMPORT_C HBufC8& Response() const;
williamr@2
    83
williamr@2
    84
 	// Accessor to the HTTP status code (e.g. 400, 300, 200, 500)
williamr@2
    85
	//
williamr@2
    86
	// Rtn: the status code - series number only.
williamr@2
    87
	//
williamr@2
    88
	//##ModelId=3B712B9A03C1
williamr@2
    89
	IMPORT_C THttpStatusCode StatusCode() const;
williamr@2
    90
williamr@2
    91
 	// Accessor to the HTTP detailed status code (e.g. 404, 304, 200, 501)
williamr@2
    92
	//
williamr@2
    93
	// Rtn: the status code - series and specific code value
williamr@2
    94
	//
williamr@2
    95
	//##ModelId=3B712B9A03C0
williamr@2
    96
	IMPORT_C THttpStatusCode DetailedStatusCode() const;
williamr@2
    97
williamr@2
    98
	// Accessor to set the HTTP response status.
williamr@2
    99
	//
williamr@2
   100
	// In:
williamr@2
   101
	//  aCode - the WSP-encoded status code
williamr@2
   102
	//
williamr@2
   103
	//##ModelId=3B712B9A03B6
williamr@2
   104
	IMPORT_C void SetStatusCode(TInt aCode);
williamr@2
   105
williamr@2
   106
	// Method to find a named field, that returns null terminated 
williamr@2
   107
	// WSP text strings.
williamr@2
   108
	//
williamr@2
   109
	// In:
williamr@2
   110
	//  aField		- the field type
williamr@2
   111
	//  aStartIndex	- the index to search from (defaults to the buffer start)
williamr@2
   112
	//
williamr@2
   113
	// Out:
williamr@2
   114
	//  aDesc - a pointer-type descriptor into the response buffer at the
williamr@2
   115
	//			position where the field was located. The caller must NOT
williamr@2
   116
	//			modify the descriptor contents
williamr@2
   117
	//
williamr@2
   118
	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
williamr@2
   119
	//
williamr@2
   120
	//##ModelId=3B712B9A0390
williamr@2
   121
	IMPORT_C TBool FindField(THttpHeaderField aField
williamr@2
   122
                             , TPtrC8& aDesc
williamr@2
   123
                             , TInt aStartIndex = 0) const;
williamr@2
   124
williamr@2
   125
	// Method to find a named field, that returns 8-bit octet data (binary
williamr@2
   126
	// or strings - not stipulated which).
williamr@2
   127
	//
williamr@2
   128
	// In:
williamr@2
   129
	//  aField		- the field type
williamr@2
   130
	//  aStartIndex	- the index to search from (defaults to the buffer start)
williamr@2
   131
	//
williamr@2
   132
	// Out:
williamr@2
   133
	//  aDesc - a pointer-type descriptor into the response buffer at the
williamr@2
   134
	//			position where the field was located. The caller must NOT
williamr@2
   135
	//			modify the descriptor contents
williamr@2
   136
	//
williamr@2
   137
	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
williamr@2
   138
	//
williamr@2
   139
	//##ModelId=3B712B9A0384
williamr@2
   140
	IMPORT_C TBool FindBinaryDescField(THttpHeaderField aField 
williamr@2
   141
							, TPtrC8& aDesc
williamr@2
   142
							, TInt aStartIndex = 0) const;
williamr@2
   143
williamr@2
   144
	// Method to find a named field, that returns an EPOC date/time structure.
williamr@2
   145
	//
williamr@2
   146
	// In:
williamr@2
   147
	//  aField		- the field type
williamr@2
   148
	//  aStartIndex	- the index to search from (defaults to the buffer start)
williamr@2
   149
	//
williamr@2
   150
	// Out:
williamr@2
   151
	//  aTime - a structure containing the time (and date) found in the header
williamr@2
   152
	//
williamr@2
   153
	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
williamr@2
   154
	//
williamr@2
   155
	//##ModelId=3B712B9A03A2
williamr@2
   156
	IMPORT_C TBool FindField(THttpHeaderField aField
williamr@2
   157
                             , TTime& aTime
williamr@2
   158
                             , TInt aStartIndex = 0) const;
williamr@2
   159
williamr@2
   160
	// Method to find a named field within the Cache Control header
williamr@2
   161
	//
williamr@2
   162
	// In:
williamr@2
   163
	//  aField		- the field type
williamr@2
   164
	//
williamr@2
   165
	// Out:
williamr@2
   166
	//
williamr@2
   167
	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
williamr@2
   168
	//
williamr@2
   169
	//##ModelId=3B712B9A0370
williamr@2
   170
	IMPORT_C TInt FindCacheControlFieldValue(TCacheControlFieldValue aField) const;
williamr@2
   171
williamr@2
   172
	// Method to find a named field within the Cache Control header, 
williamr@2
   173
	// that returns an EPOC date/time structure.
williamr@2
   174
	//
williamr@2
   175
	// In:
williamr@2
   176
	//  aField		- the field type
williamr@2
   177
	//
williamr@2
   178
	// Out:
williamr@2
   179
	//  aTime - a structure containing the time (and date) found in the header field
williamr@2
   180
	//
williamr@2
   181
	// Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
williamr@2
   182
	//
williamr@2
   183
	//##ModelId=3B712B9A035C
williamr@2
   184
	IMPORT_C TBool ExtractCacheControlTime(TCacheControlFieldValue aField, TTime& aTime) const;
williamr@2
   185
williamr@2
   186
	// Method to search for the content type encoded in the response header
williamr@2
   187
	//
williamr@2
   188
	// Out:
williamr@2
   189
	//  aDesc - a pointer-type descriptor into the appropriate element of an
williamr@2
   190
	//			array prefilled with all the content types that have WSP
williamr@2
   191
	//			encodings. e.g. "text/vnd.wap.wml".  The contents of the
williamr@2
   192
	//			descriptor must NOT be modified.
williamr@2
   193
	//
williamr@2
   194
	//##ModelId=3B712B9A0348
williamr@2
   195
	IMPORT_C void ContentType(TPtrC8& aDesc) const;
williamr@2
   196
williamr@2
   197
	// Method to search for the realm encoded in the response header, when the
williamr@2
   198
	// response challenges the client for HTTP authentication (code 401)
williamr@2
   199
	//
williamr@2
   200
	// Out:
williamr@2
   201
	//  aDesc - a pointer-type descriptor into the response header buffer
williamr@2
   202
	//			positioned at the realm string within the challenge. The
williamr@2
   203
	//			contents of the descriptor must NOT be modified.
williamr@2
   204
	//
williamr@2
   205
	// Rtn: TBool - set to ETrue if a www-authenticate realm was found, EFalse
williamr@2
   206
	//				otherwise
williamr@2
   207
	//
williamr@2
   208
	//##ModelId=3B712B9A033F
williamr@2
   209
	IMPORT_C TBool FindRealm(TPtrC8& aRealm) const;
williamr@2
   210
williamr@2
   211
	// Method to search for the character set encoded in the Content-Type
williamr@2
   212
	// field ofthe response header
williamr@2
   213
	//
williamr@2
   214
	// Out:
williamr@2
   215
	//  aDesc - a pointer-type descriptor into the appropriate element of an
williamr@2
   216
	//			array prefilled with all the character sets that have WSP
williamr@2
   217
	//			encodings. e.g. "utf-8".  The contents of the descriptor must
williamr@2
   218
	//			NOT be modified.
williamr@2
   219
	//
williamr@2
   220
	// Rtn: TBool - set to ETrue if a character set was found, EFalse if not
williamr@2
   221
	//
williamr@2
   222
	//##ModelId=3B712B9A032A
williamr@2
   223
	IMPORT_C TBool CharSet(TPtrC8& aDesc) const;
williamr@2
   224
williamr@2
   225
protected: // Methods
williamr@2
   226
williamr@2
   227
	// Normal constructor - do non-allocating creation of this class
williamr@2
   228
	//
williamr@2
   229
    IMPORT_C CHTTPResponse();
williamr@2
   230
williamr@2
   231
	// Second phase construction - any allocation for this class must take place
williamr@2
   232
	// here. Sets up the resources required by an HTTP Response.
williamr@2
   233
	//
williamr@2
   234
	//##ModelId=3B712B9A0322
williamr@2
   235
	IMPORT_C void ConstructL();
williamr@2
   236
williamr@2
   237
	//friend class declaration - only need the following function
williamr@2
   238
	friend class CPushMessage;
williamr@2
   239
	// Method to locate a named field in the response header, starting at the
williamr@2
   240
	// specified index position.
williamr@2
   241
	//
williamr@2
   242
	// In:
williamr@2
   243
	//  aField		- the header field type
williamr@2
   244
	//  aStartIndex - the (optional) position in the header to start searching
williamr@2
   245
	//
williamr@2
   246
	// Rtn: TInt - the index position of the required field _value_ (not the
williamr@2
   247
	//             field name), or KErrNotFound otherwise.
williamr@2
   248
	//
williamr@2
   249
	//##ModelId=3B712B9A030D
williamr@2
   250
	IMPORT_C TInt LocateField(THttpHeaderField aField, TInt aStartIndex = 0) const; 
williamr@2
   251
williamr@2
   252
	// Perform a look-up of content type given a WSP encoding value, used as
williamr@2
   253
	// an index.
williamr@2
   254
	//
williamr@2
   255
	// In:
williamr@2
   256
	//  aIndex - the WSP encoding value
williamr@2
   257
	//
williamr@2
   258
	// Rtn: const TText8* - the required content type text - NOT to be changed
williamr@2
   259
	//
williamr@2
   260
	//##ModelId=3B712B9A0352
williamr@2
   261
	IMPORT_C const TText8* ContentType(TInt aContentTypeCode) const;
williamr@2
   262
williamr@2
   263
 	// Perform a look-up of character set given a WSP encoding value, used as
williamr@2
   264
	// an index.
williamr@2
   265
	//
williamr@2
   266
	// In:
williamr@2
   267
	//  aCharsetCode - the index into the content types table/
williamr@2
   268
	//
williamr@2
   269
	// Rtn: const TText8* - the required 8-bit character set text - NOT to be
williamr@2
   270
	//						changed by the caller
williamr@2
   271
	//
williamr@2
   272
	//##ModelId=3B712B9A0334
williamr@2
   273
	IMPORT_C const TText8* CharSet(TInt aCharsetCode) const;
williamr@2
   274
williamr@2
   275
private: // Attributes
williamr@2
   276
williamr@2
   277
	// The 8-bit buffer used to store the HTTP response fields
williamr@2
   278
	//
williamr@2
   279
	//##ModelId=3B712B9A02AA
williamr@2
   280
    HBufC8* iResponse;
williamr@2
   281
williamr@2
   282
	// The HTTP Status code (coarse - ie. series only, e.g. 100, 200 etc.)
williamr@2
   283
	//
williamr@2
   284
	//##ModelId=3B712B9A0296
williamr@2
   285
    THttpStatusCode iStatusCode;
williamr@2
   286
williamr@2
   287
	// The detailed HTTP Status code (within series, e.g. 102, 204, 401 etc.)
williamr@2
   288
	//
williamr@2
   289
	//##ModelId=3B712B9A0282
williamr@2
   290
    THttpStatusCode iDetailedStatusCode;
williamr@2
   291
williamr@2
   292
	// Declare the CLogClient pointer
williamr@2
   293
   	__DECLARE_LOG
williamr@2
   294
williamr@2
   295
private: // Methods
williamr@2
   296
williamr@2
   297
	// Do a conversion from 32-bit UIntVar encoding into 32-bit integer
williamr@2
   298
	//
williamr@2
   299
	TInt ParseUIntVar(const TDesC8& aBuffer, TInt& aVal) const;
williamr@2
   300
williamr@2
   301
	// Extract a WSP encoded MultiOctet Integer encoding into 32-bit integer
williamr@2
   302
	//
williamr@2
   303
	// In:
williamr@2
   304
	//  aSource	- the source Multi-Octet integer
williamr@2
   305
	//
williamr@2
   306
	// Out:
williamr@2
   307
	//  aInt		- the 32-bit resulting integer
williamr@2
   308
	//
williamr@2
   309
	//##ModelId=3B712B9A02F8
williamr@2
   310
	void ExtractMultiOctetInteger(TInt& aInt, const TPtrC8& aSource) const;
williamr@2
   311
williamr@2
   312
	// Method to find a named field within the Cache Control header
williamr@2
   313
	//
williamr@2
   314
	// In:
williamr@2
   315
	//  aSource		- the descriptor containing the date value
williamr@2
   316
	//	aFrom		- The position in the descriptor to start from
williamr@2
   317
	//
williamr@2
   318
	// Out:
williamr@2
   319
	//  aTime - a structure containing the time (and date) found in the descriptor
williamr@2
   320
	//
williamr@2
   321
	//##ModelId=3B712B9A02E4
williamr@2
   322
	void ExtractFieldDateValue(const TPtrC8& aSource, TInt aFrom, TTime& aTime) const;
williamr@2
   323
williamr@2
   324
	// Method to find a named field within the Cache Control header
williamr@2
   325
	//
williamr@2
   326
	// In:
williamr@2
   327
	//  aField		- the field type
williamr@2
   328
	//
williamr@2
   329
	// Out:
williamr@2
   330
	//	the found aCacheControl string
williamr@2
   331
	//
williamr@2
   332
	// Rtn: TInt - set to KErrNotFound if the field was not found,
williamr@2
   333
	//		otherwise the position in the cache control descriptor that the field was found
williamr@2
   334
	//
williamr@2
   335
	//##ModelId=3B712B9A0372
williamr@2
   336
	TInt FindCacheControlFieldValue(TCacheControlFieldValue aField,TPtrC8& aCacheControl) const;
williamr@2
   337
williamr@2
   338
	//##ModelId=3B712B9A02DA
williamr@2
   339
    void Panic(THttpPanicCode aPanicCode) const;
williamr@2
   340
williamr@2
   341
	// Spare methods for future BC. Const- and non-const versions to assist
williamr@2
   342
	// the caller in preserving const-ness. IMPORT_C ensures they reserve a
williamr@2
   343
	// slot in the vtbl, which is essential to preseve future BC.
williamr@2
   344
	//
williamr@2
   345
	//##ModelId=3B712B9A02D0
williamr@2
   346
	IMPORT_C virtual TAny* Extend_CHTTPResponse(TAny* aArgs);
williamr@2
   347
	//##ModelId=3B712B9A02C6
williamr@2
   348
	IMPORT_C virtual TAny* Extend_CHTTPResponse_const(TAny* aArgs) const;
williamr@2
   349
williamr@2
   350
#if defined _DEBUG
williamr@2
   351
	// Debug method definition to allow class invariant testing
williamr@2
   352
	// Called by the standard macro __TEST_INVARIANT
williamr@2
   353
	//
williamr@2
   354
	//##ModelId=3B712B9A02BD
williamr@2
   355
	void __DbgTestInvariant() const;
williamr@2
   356
williamr@2
   357
	//##ModelId=3B712B9A02B2
williamr@2
   358
	void DumpToLog(const TDesC8& aData) const;
williamr@2
   359
#endif
williamr@2
   360
williamr@2
   361
	};
williamr@2
   362
williamr@2
   363
#endif // __CHTTPRESPONSE_H__