1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Purpose: This file provides the definition of the CHTTPResponse class.
15 // The HTTP Response class encodes HTTP response headers only. It
16 // contains the methods used to transcode from WSP->HTTP fields
20 #ifndef __CHTTPRESPONSE_H__
21 #define __CHTTPRESPONSE_H__
28 #include <thttpfields.h>
31 // Forward class declarations
35 // Class definition for CHTTPResponse
37 //##ModelId=3B712B9A0231
38 class CHTTPResponse : public CBase
46 // Factory method to construct this class.
48 // Rtn: a new CHTTPResponse object, by ptr. Ownership is transferred to the
51 //##ModelId=3B712B9B000A
52 IMPORT_C static CHTTPResponse* NewL();
54 // Destructor for this class. Removes this object and releases memory held
57 //##ModelId=3B712B9B0000
58 IMPORT_C virtual ~CHTTPResponse();
60 // Clean out the fields buffer
62 //##ModelId=3B712B9A03D6
63 IMPORT_C void Reset();
65 // Set the fields buffer with the response received from the WAP Stack
68 // aResponse - an 8-bit descriptor field containing the origin server's
69 // WSP-encoded response header. Ownership is transferred to
72 //##ModelId=3B712B9A03D4
73 IMPORT_C void AddResponse(HBufC8* aResponse);
75 // Accessor to the HTTP response fields buffer
77 // Rtn: a reference to the response. Ownership is _NOT_ transferred
79 // NOTE THIS SHOULD RETURN CONST - BUT CAN'T BE CHANGED SINCE IT WOULD
81 //##ModelId=3B712B9A03CA
82 IMPORT_C HBufC8& Response() const;
84 // Accessor to the HTTP status code (e.g. 400, 300, 200, 500)
86 // Rtn: the status code - series number only.
88 //##ModelId=3B712B9A03C1
89 IMPORT_C THttpStatusCode StatusCode() const;
91 // Accessor to the HTTP detailed status code (e.g. 404, 304, 200, 501)
93 // Rtn: the status code - series and specific code value
95 //##ModelId=3B712B9A03C0
96 IMPORT_C THttpStatusCode DetailedStatusCode() const;
98 // Accessor to set the HTTP response status.
101 // aCode - the WSP-encoded status code
103 //##ModelId=3B712B9A03B6
104 IMPORT_C void SetStatusCode(TInt aCode);
106 // Method to find a named field, that returns null terminated
110 // aField - the field type
111 // aStartIndex - the index to search from (defaults to the buffer start)
114 // aDesc - a pointer-type descriptor into the response buffer at the
115 // position where the field was located. The caller must NOT
116 // modify the descriptor contents
118 // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
120 //##ModelId=3B712B9A0390
121 IMPORT_C TBool FindField(THttpHeaderField aField
123 , TInt aStartIndex = 0) const;
125 // Method to find a named field, that returns 8-bit octet data (binary
126 // or strings - not stipulated which).
129 // aField - the field type
130 // aStartIndex - the index to search from (defaults to the buffer start)
133 // aDesc - a pointer-type descriptor into the response buffer at the
134 // position where the field was located. The caller must NOT
135 // modify the descriptor contents
137 // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
139 //##ModelId=3B712B9A0384
140 IMPORT_C TBool FindBinaryDescField(THttpHeaderField aField
142 , TInt aStartIndex = 0) const;
144 // Method to find a named field, that returns an EPOC date/time structure.
147 // aField - the field type
148 // aStartIndex - the index to search from (defaults to the buffer start)
151 // aTime - a structure containing the time (and date) found in the header
153 // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
155 //##ModelId=3B712B9A03A2
156 IMPORT_C TBool FindField(THttpHeaderField aField
158 , TInt aStartIndex = 0) const;
160 // Method to find a named field within the Cache Control header
163 // aField - the field type
167 // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
169 //##ModelId=3B712B9A0370
170 IMPORT_C TInt FindCacheControlFieldValue(TCacheControlFieldValue aField) const;
172 // Method to find a named field within the Cache Control header,
173 // that returns an EPOC date/time structure.
176 // aField - the field type
179 // aTime - a structure containing the time (and date) found in the header field
181 // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise
183 //##ModelId=3B712B9A035C
184 IMPORT_C TBool ExtractCacheControlTime(TCacheControlFieldValue aField, TTime& aTime) const;
186 // Method to search for the content type encoded in the response header
189 // aDesc - a pointer-type descriptor into the appropriate element of an
190 // array prefilled with all the content types that have WSP
191 // encodings. e.g. "text/vnd.wap.wml". The contents of the
192 // descriptor must NOT be modified.
194 //##ModelId=3B712B9A0348
195 IMPORT_C void ContentType(TPtrC8& aDesc) const;
197 // Method to search for the realm encoded in the response header, when the
198 // response challenges the client for HTTP authentication (code 401)
201 // aDesc - a pointer-type descriptor into the response header buffer
202 // positioned at the realm string within the challenge. The
203 // contents of the descriptor must NOT be modified.
205 // Rtn: TBool - set to ETrue if a www-authenticate realm was found, EFalse
208 //##ModelId=3B712B9A033F
209 IMPORT_C TBool FindRealm(TPtrC8& aRealm) const;
211 // Method to search for the character set encoded in the Content-Type
212 // field ofthe response header
215 // aDesc - a pointer-type descriptor into the appropriate element of an
216 // array prefilled with all the character sets that have WSP
217 // encodings. e.g. "utf-8". The contents of the descriptor must
220 // Rtn: TBool - set to ETrue if a character set was found, EFalse if not
222 //##ModelId=3B712B9A032A
223 IMPORT_C TBool CharSet(TPtrC8& aDesc) const;
225 protected: // Methods
227 // Normal constructor - do non-allocating creation of this class
229 IMPORT_C CHTTPResponse();
231 // Second phase construction - any allocation for this class must take place
232 // here. Sets up the resources required by an HTTP Response.
234 //##ModelId=3B712B9A0322
235 IMPORT_C void ConstructL();
237 //friend class declaration - only need the following function
238 friend class CPushMessage;
239 // Method to locate a named field in the response header, starting at the
240 // specified index position.
243 // aField - the header field type
244 // aStartIndex - the (optional) position in the header to start searching
246 // Rtn: TInt - the index position of the required field _value_ (not the
247 // field name), or KErrNotFound otherwise.
249 //##ModelId=3B712B9A030D
250 IMPORT_C TInt LocateField(THttpHeaderField aField, TInt aStartIndex = 0) const;
252 // Perform a look-up of content type given a WSP encoding value, used as
256 // aIndex - the WSP encoding value
258 // Rtn: const TText8* - the required content type text - NOT to be changed
260 //##ModelId=3B712B9A0352
261 IMPORT_C const TText8* ContentType(TInt aContentTypeCode) const;
263 // Perform a look-up of character set given a WSP encoding value, used as
267 // aCharsetCode - the index into the content types table/
269 // Rtn: const TText8* - the required 8-bit character set text - NOT to be
270 // changed by the caller
272 //##ModelId=3B712B9A0334
273 IMPORT_C const TText8* CharSet(TInt aCharsetCode) const;
275 private: // Attributes
277 // The 8-bit buffer used to store the HTTP response fields
279 //##ModelId=3B712B9A02AA
282 // The HTTP Status code (coarse - ie. series only, e.g. 100, 200 etc.)
284 //##ModelId=3B712B9A0296
285 THttpStatusCode iStatusCode;
287 // The detailed HTTP Status code (within series, e.g. 102, 204, 401 etc.)
289 //##ModelId=3B712B9A0282
290 THttpStatusCode iDetailedStatusCode;
292 // Declare the CLogClient pointer
297 // Do a conversion from 32-bit UIntVar encoding into 32-bit integer
299 TInt ParseUIntVar(const TDesC8& aBuffer, TInt& aVal) const;
301 // Extract a WSP encoded MultiOctet Integer encoding into 32-bit integer
304 // aSource - the source Multi-Octet integer
307 // aInt - the 32-bit resulting integer
309 //##ModelId=3B712B9A02F8
310 void ExtractMultiOctetInteger(TInt& aInt, const TPtrC8& aSource) const;
312 // Method to find a named field within the Cache Control header
315 // aSource - the descriptor containing the date value
316 // aFrom - The position in the descriptor to start from
319 // aTime - a structure containing the time (and date) found in the descriptor
321 //##ModelId=3B712B9A02E4
322 void ExtractFieldDateValue(const TPtrC8& aSource, TInt aFrom, TTime& aTime) const;
324 // Method to find a named field within the Cache Control header
327 // aField - the field type
330 // the found aCacheControl string
332 // Rtn: TInt - set to KErrNotFound if the field was not found,
333 // otherwise the position in the cache control descriptor that the field was found
335 //##ModelId=3B712B9A0372
336 TInt FindCacheControlFieldValue(TCacheControlFieldValue aField,TPtrC8& aCacheControl) const;
338 //##ModelId=3B712B9A02DA
339 void Panic(THttpPanicCode aPanicCode) const;
341 // Spare methods for future BC. Const- and non-const versions to assist
342 // the caller in preserving const-ness. IMPORT_C ensures they reserve a
343 // slot in the vtbl, which is essential to preseve future BC.
345 //##ModelId=3B712B9A02D0
346 IMPORT_C virtual TAny* Extend_CHTTPResponse(TAny* aArgs);
347 //##ModelId=3B712B9A02C6
348 IMPORT_C virtual TAny* Extend_CHTTPResponse_const(TAny* aArgs) const;
351 // Debug method definition to allow class invariant testing
352 // Called by the standard macro __TEST_INVARIANT
354 //##ModelId=3B712B9A02BD
355 void __DbgTestInvariant() const;
357 //##ModelId=3B712B9A02B2
358 void DumpToLog(const TDesC8& aData) const;
363 #endif // __CHTTPRESPONSE_H__