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