|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Declaration of CPushMtmFetchOperation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef PUSHMTMFETCHOPERATION_H |
|
21 #define PUSHMTMFETCHOPERATION_H |
|
22 |
|
23 // INCLUDE FILES |
|
24 |
|
25 #include <e32std.h> |
|
26 #include <e32base.h> |
|
27 #include <http.h> |
|
28 #include <stringpool.h> |
|
29 #include <apmstd.h> |
|
30 #include <es_sock.h> |
|
31 #include "HttpCacheManager.h" |
|
32 #include "PushMtmCacheSupply.h" |
|
33 |
|
34 // FORWARD DECLARATIONS |
|
35 |
|
36 class CMsvEntry; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 |
|
40 /** |
|
41 * Asynchronous fetch operation that downloads the service indicated by an SL |
|
42 * pushed service message. |
|
43 * |
|
44 * The operation can run in silent mode without requiring any user intervention. |
|
45 */ |
|
46 class CPushMtmFetchOperation : public CActive, |
|
47 public MHTTPTransactionCallback, |
|
48 public MCacheSupplyCallbacks |
|
49 { |
|
50 public: // Constructors and destructor |
|
51 |
|
52 /** |
|
53 * Two-phased constructor. Leaves on failure. |
|
54 * @param aRequestedUrl The requested URL. |
|
55 * @param aObserverRequestStatus Observer's status. |
|
56 * @return The constructed operation. |
|
57 */ |
|
58 static CPushMtmFetchOperation* NewL |
|
59 ( |
|
60 const TDesC& aRequestedUrl, |
|
61 TRequestStatus& aObserverRequestStatus |
|
62 ); |
|
63 |
|
64 /** |
|
65 * Destructor. |
|
66 */ |
|
67 virtual ~CPushMtmFetchOperation(); |
|
68 |
|
69 public: // Functions from base classes |
|
70 |
|
71 /** |
|
72 * Start or restart the operation. |
|
73 */ |
|
74 void StartL(); |
|
75 |
|
76 RHTTPTransaction* Transaction(){ return &iHttpTrans; } |
|
77 void HandleEventL(THTTPEvent aEvent) { MHFRunL(iHttpTrans, aEvent); } |
|
78 |
|
79 protected: // Constructors |
|
80 |
|
81 /** |
|
82 * Constructor. |
|
83 * @param aObserverRequestStatus Observer's status. |
|
84 */ |
|
85 CPushMtmFetchOperation( TRequestStatus& aObserverRequestStatus ); |
|
86 |
|
87 /** |
|
88 * Second phase constructor. |
|
89 * @param aRequestedUrl The requested URL. |
|
90 * @return None. |
|
91 */ |
|
92 void ConstructL( const TDesC& aRequestedUrl ); |
|
93 |
|
94 protected: // New functions |
|
95 |
|
96 /** |
|
97 * Get the ID of the defauld internet access point set in the Browser |
|
98 * Preferences that is used for connection creation. |
|
99 * @param aIapId The ID of the access point, if found. The value of |
|
100 * this variable is not changed if no default ap can be found. |
|
101 * @return Indicate if default ap could be found. |
|
102 */ |
|
103 TBool GetDefaultInetAccessPointL( TUint32& aIapId ) const; |
|
104 |
|
105 protected: // state machine parts |
|
106 |
|
107 /** |
|
108 * Initiate connecting. |
|
109 */ |
|
110 void InitializeL(); |
|
111 |
|
112 /** |
|
113 * StartRequestL |
|
114 */ |
|
115 void StartRequestL(); |
|
116 |
|
117 /** |
|
118 * CheckCacheL |
|
119 */ |
|
120 void CheckCacheL(); |
|
121 |
|
122 /** |
|
123 * Initiate connecting. |
|
124 */ |
|
125 void RequestL(); |
|
126 |
|
127 /** |
|
128 * Clean up and notify parent. |
|
129 */ |
|
130 void Done(); |
|
131 |
|
132 /** |
|
133 * Create transaction, set request headers (and body for POST request). |
|
134 */ |
|
135 void CreateTransactionL(); |
|
136 |
|
137 /** |
|
138 * Submit the transaction (make the HTTP request). |
|
139 */ |
|
140 void SubmitTransactionL(); |
|
141 |
|
142 /** |
|
143 * Handle response from server. |
|
144 * @param aResponse Response from server. |
|
145 */ |
|
146 void HandleResponseHeadersL( RHTTPResponse aResponse ); |
|
147 |
|
148 /** |
|
149 * HTTP Version Not Supported. Resubmit transaction using HTTP/1.0. |
|
150 * @return ETrue if transaction was resubmitted, EFalse if not (i.e |
|
151 * we already use HTTP/1.0). |
|
152 */ |
|
153 TBool VersionRetryL(); |
|
154 |
|
155 /** |
|
156 * Append a new chunk of response data to the reponse buffer. |
|
157 * @return KErrNone or KErrNoMemory. |
|
158 */ |
|
159 TInt AppendResponse( const TDesC8& aDataChunk ); |
|
160 |
|
161 protected: // helpers |
|
162 |
|
163 /** |
|
164 * Helper function to set a header. |
|
165 * @param aHeaders Set the header to this header set. |
|
166 * @param aHdrField Header field name. |
|
167 * @param aHdrValue Header value. |
|
168 */ |
|
169 void SetHeaderL |
|
170 ( |
|
171 RHTTPHeaders aHeaders, |
|
172 HTTP::TStrings aHdrField, |
|
173 const TDesC8& aHdrValue |
|
174 ); |
|
175 |
|
176 /** |
|
177 * Helper function to set a header. |
|
178 * @param aHeaders Set the header to this header set. |
|
179 * @param aHdrField Header field name. |
|
180 * @param aHdrValue Header value. |
|
181 */ |
|
182 void SetHeaderL |
|
183 ( |
|
184 RHTTPHeaders aHeaders, |
|
185 HTTP::TStrings aHdrField, |
|
186 HTTP::TStrings aHdrValue |
|
187 ); |
|
188 |
|
189 /** |
|
190 * Helper function to set a header. |
|
191 * @param aHeaders Set the header to this header set. |
|
192 * @param aHdrField Header field name. |
|
193 * @param aHdrValue Header value. |
|
194 */ |
|
195 void SetHeaderL |
|
196 ( |
|
197 RHTTPHeaders aHeaders, |
|
198 HTTP::TStrings aHdrField, |
|
199 const RStringF aHdrValue |
|
200 ); |
|
201 |
|
202 /** |
|
203 * Helper function to get the Content-Type header value. |
|
204 * @param aHeaders HTTP header set. |
|
205 * @return Content-Type header value. |
|
206 */ |
|
207 const TDesC8& GetContentTypeL( RHTTPHeaders aHeaders ); |
|
208 |
|
209 /** |
|
210 * Helper function to get the source URI of a transaction. |
|
211 * @param aTransaction Transaction. |
|
212 * @return Source URI. |
|
213 */ |
|
214 const TDesC8& GetSourceUriL( RHTTPTransaction aTransaction ); |
|
215 |
|
216 /** |
|
217 * Get a shared string from the session stringpool. |
|
218 * @param aId Id of string. |
|
219 * @return Shared string from HTTP string table. No need to close. |
|
220 */ |
|
221 inline RStringF StringF( HTTP::TStrings aId ); |
|
222 |
|
223 protected: // debug utilities |
|
224 |
|
225 /** |
|
226 * In debug build, log headers. In release build, do nothing. |
|
227 * @param aHeaders Headers to log. |
|
228 */ |
|
229 void LogHeadersL( RHTTPHeaders aHeaders ); |
|
230 |
|
231 protected: // Functions from base classes |
|
232 |
|
233 /** |
|
234 * Cancel fetching. |
|
235 * @return None. |
|
236 */ |
|
237 void DoCancel(); |
|
238 |
|
239 /** |
|
240 * Start fetching and make an entry into the operation mapper. |
|
241 * @return None. |
|
242 */ |
|
243 void RunL(); |
|
244 |
|
245 /** |
|
246 * Leave handler protocol implementation: it is called when |
|
247 * RunL leaves. |
|
248 */ |
|
249 TInt RunError( TInt aError ); |
|
250 |
|
251 protected: // from MHTTPTransactionCallback |
|
252 |
|
253 /** |
|
254 * Handle transaction event. |
|
255 * @param aTransaction The transaction that the event has occurred on. |
|
256 * @param aEvent The event that has occurred. |
|
257 */ |
|
258 void MHFRunL( RHTTPTransaction aTransaction, |
|
259 const THTTPEvent& aEvent ); |
|
260 |
|
261 /** |
|
262 * Handle errors occured in MHFRunL(). |
|
263 * @param aError The leave code that RunL left with. |
|
264 * @param aTransaction The transaction that was being processed. |
|
265 * @param aEvent The Event that was being processed. |
|
266 * @return KErrNone. |
|
267 */ |
|
268 TInt MHFRunError( TInt aError, |
|
269 RHTTPTransaction aTransaction, |
|
270 const THTTPEvent& aEvent ); |
|
271 |
|
272 protected: // Data |
|
273 |
|
274 TRequestStatus& iObserver; ///< Observer's status. |
|
275 HBufC8* iRequestedUrl; ///< Request URI or NULL. Owned. |
|
276 |
|
277 enum TState ///< State. |
|
278 { |
|
279 EInit, ///< Initial state. |
|
280 EStartRequest, ///< Create HTTP session & request |
|
281 ECheckCache, ///< Check if content is in cache |
|
282 ERequest, ///< HTTP request. |
|
283 EDone |
|
284 }; |
|
285 |
|
286 TState iState; ///< Current state. |
|
287 TInt iResult; ///< Resulting error code. |
|
288 |
|
289 RSocketServ iSockServ; ///< Socket Server session handle. |
|
290 RConnection iConn; ///< Connection handle. |
|
291 |
|
292 CHttpCacheManager* iCacheMgr;///< Cache Manager. Owned. |
|
293 |
|
294 RHTTPSession iHttpSess; ///< HTTP session. Owned. |
|
295 RHTTPTransaction iHttpTrans;///< Transaction. Owned. |
|
296 |
|
297 HBufC8* iSourceUri; ///< Source URI. Owned. |
|
298 HBufC8* iBody; ///< Response body. Owned. |
|
299 TDataType iDataType; ///< Data type. |
|
300 THttpCacheEntry iCacheEntry;///< Holds the cache entry |
|
301 CPushMtmCacheSupply* iCacheSupply; |
|
302 TBool iCachedResponse; |
|
303 }; |
|
304 |
|
305 #include "PushMtmFetchOperation.inl" |
|
306 |
|
307 #endif // PUSHMTMFETCHOPERATION_H |
|
308 |
|
309 // End of file. |