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