|
1 /** @file |
|
2 * Copyright (c) 2007 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 "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: Handles upload of single file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_HTTPUPLOADWORKER_H |
|
20 #define C_HTTPUPLOADWORKER_H |
|
21 |
|
22 // system includes |
|
23 #include <escapeutils.h> |
|
24 #include <http/mhttpdatasupplier.h> |
|
25 |
|
26 // user includes |
|
27 #include "httptransferworker.h" |
|
28 |
|
29 // forward declarations |
|
30 class MHttpWorkerObserver; |
|
31 |
|
32 /** |
|
33 * Handles upload of single file. Used by CHttpUploader. |
|
34 * |
|
35 * @lib httptransfer.lib |
|
36 * @since S60 v3.2 |
|
37 */ |
|
38 NONSHARABLE_CLASS ( CHttpUploadWorker ) : public CHttpTransferWorker, |
|
39 public MHTTPDataSupplier, |
|
40 MHttpNotifyTimerObserver |
|
41 { |
|
42 public: |
|
43 |
|
44 /** |
|
45 * Constructor |
|
46 * |
|
47 * @since S60 v3.2 |
|
48 * @param aObserver Transfer observer |
|
49 * @param aIAPId IAP id |
|
50 * @param aBufferSize Size of the buffer |
|
51 * @param aCallback Call back to workerobserver |
|
52 */ |
|
53 static CHttpUploadWorker* NewL( MHttpTransferObserver& aObserver, |
|
54 TUint aIAPId, |
|
55 TUint aBufferSize, |
|
56 MHttpWorkerObserver& aCallback ); |
|
57 |
|
58 /** |
|
59 * Constructor |
|
60 * |
|
61 * @since S60 v3.2 |
|
62 * @param aObserver Transfer observer |
|
63 * @param aIAPId IAP id |
|
64 * @param aBufferSize Size of the buffer |
|
65 * @param aCallback Call back to workerobserver |
|
66 */ |
|
67 static CHttpUploadWorker* NewLC( MHttpTransferObserver& aObserver, |
|
68 TUint aIAPId, |
|
69 TUint aBufferSize, |
|
70 MHttpWorkerObserver& aCallback ); |
|
71 |
|
72 /** |
|
73 * Destructor |
|
74 * |
|
75 * @since S60 v3.2 |
|
76 */ |
|
77 virtual ~CHttpUploadWorker(); |
|
78 |
|
79 // New functions |
|
80 |
|
81 /** |
|
82 * Sends a file to some URI through HTTP channel. |
|
83 * The POST HTTP method is used. |
|
84 * |
|
85 * @since S60 v.3.2 |
|
86 */ |
|
87 void SendL(); |
|
88 |
|
89 /** |
|
90 * Invokes the http method. |
|
91 * This actually creates the transaction, sets the headers and body |
|
92 * and then starts the transaction. |
|
93 * |
|
94 * @since S60 v3.2 |
|
95 */ |
|
96 void InvokeHttpMethodL(); |
|
97 |
|
98 // from base class CHttpTransferWorker |
|
99 |
|
100 /** |
|
101 * Stops the transfer of the file |
|
102 * |
|
103 * @since S60 v3.2 |
|
104 */ |
|
105 void CancelTransfer(); |
|
106 |
|
107 /** |
|
108 * Starts the processing of a file. Asynchronous. |
|
109 * |
|
110 * @since S60 v3.2 |
|
111 */ |
|
112 virtual void StartProcessL(); |
|
113 |
|
114 // from base class MHTTPTransactionCallback |
|
115 |
|
116 /** |
|
117 * Called by framework to notify about transaction events. |
|
118 * |
|
119 * @since S60 v3.2 |
|
120 * @param aTransaction Transaction, where the event occured. |
|
121 * @param aEvent Occured event. |
|
122 */ |
|
123 virtual void MHFRunL( RHTTPTransaction aTransaction, |
|
124 const THTTPEvent& aEvent ); |
|
125 |
|
126 /** |
|
127 * Called by framework when leave occurs in handling of |
|
128 * transaction event. |
|
129 * |
|
130 * @since S60 v3.2 |
|
131 * @param aError The leave code that occured. |
|
132 * @param aTransaction The transaction that was being processed |
|
133 * @param aEvent The event that was being processed |
|
134 * @return Error code |
|
135 */ |
|
136 virtual TInt MHFRunError( TInt aError, |
|
137 RHTTPTransaction aTransaction, |
|
138 const THTTPEvent& aEvent ); |
|
139 |
|
140 // from base class MHttpDataSupplier |
|
141 |
|
142 /** |
|
143 * Obtain a data part from the supplier. The data is guaranteed |
|
144 * to survive until a call is made to ReleaseData() |
|
145 * |
|
146 * @since S60 v3.2 |
|
147 * @param aDataPart - the data part |
|
148 * @return ETrue if this is the last part. EFalse otherwise |
|
149 */ |
|
150 TBool GetNextDataPart( TPtrC8& aDataPart ); |
|
151 |
|
152 /** |
|
153 * Release the current data part being held at the data |
|
154 * supplier. This call indicates to the supplier that the part |
|
155 * is no longer needed, and another one can be supplied, if |
|
156 * appropriate. |
|
157 * |
|
158 * @since S60 v3.2. |
|
159 */ |
|
160 void ReleaseData(); |
|
161 |
|
162 /** |
|
163 * Obtain the overall size of the data being supplied, if known |
|
164 * to the supplier. Where a body of data is supplied in several |
|
165 * parts this size will be the sum of all the part sizes. If |
|
166 * the size is not known, KErrNotFound is returned; in this case |
|
167 * the client must use the return code of GetNextDataPart to find |
|
168 * out when the data is complete. |
|
169 * |
|
170 * @since S60 v3.2 |
|
171 * @return Return code |
|
172 */ |
|
173 TInt OverallDataSize(); |
|
174 |
|
175 /** |
|
176 * Reset the data supplier. This indicates to the data supplier that |
|
177 * it should return to the first part of the data. This could be used |
|
178 * in a situation where the data consumer has encountered an error |
|
179 * and needs the data to be supplied afresh. Even if the last part |
|
180 * has been supplied (i.e. GetNextDataPart has returned ETrue), the |
|
181 * data supplier should reset to the first part. |
|
182 * |
|
183 * If the supplier cannot reset it should return an error code; |
|
184 * otherwise it should return KErrNone, where the reset will be assumed |
|
185 * to have succeeded |
|
186 * |
|
187 * @since S60 v3.2 |
|
188 * @return Error code |
|
189 */ |
|
190 TInt Reset(); |
|
191 |
|
192 |
|
193 private: |
|
194 |
|
195 /** |
|
196 * Default constructor |
|
197 * |
|
198 * @since S60 v3.2 |
|
199 * @param aObserver Transfer observer |
|
200 * @param aIAPId IAP id |
|
201 * @param aBufferSize Size of the buffer |
|
202 * @param aCallback Call back to workerobserver |
|
203 */ |
|
204 CHttpUploadWorker( MHttpTransferObserver& aObserver, |
|
205 TUint aIAPId, |
|
206 TUint aBufferSize, |
|
207 MHttpWorkerObserver& aCallback ); |
|
208 |
|
209 /** |
|
210 * Second phase constructor |
|
211 * |
|
212 * @since S60 v3.2 |
|
213 */ |
|
214 void ConstructL(); |
|
215 |
|
216 /** |
|
217 * Map HTTP transaction error to Symbian error (POST request) |
|
218 * |
|
219 * @since S60 v3.2 |
|
220 * @param aError HTTP transaction error |
|
221 * @return symbian error code |
|
222 */ |
|
223 TInt MapPostTransactionError( TInt aError ) const; |
|
224 |
|
225 /** |
|
226 * Complete the transaction and notify the client |
|
227 * |
|
228 * @since S60 v3.2 |
|
229 * @param aError HTTP transaction error |
|
230 */ |
|
231 void CompleteAndNotify( TInt aError ); |
|
232 |
|
233 /** |
|
234 * Callback function for timer expirations. |
|
235 * @since Series60 5.0 HN |
|
236 * @param aTimer Timer that has expired. |
|
237 **/ |
|
238 void TimerEventL( CHttpNotifyTimer* aTimer ); |
|
239 |
|
240 /** |
|
241 * Cancels and destroys the 100-continue response wait timer if it exists. |
|
242 * |
|
243 * @since S60 v3.2.3 |
|
244 */ |
|
245 void Destroy100ContinueTimer(); |
|
246 |
|
247 /** |
|
248 * Callback method for 100 continue timer. Cancels waiting for |
|
249 * 100-continue response and proceeds with sending the body. |
|
250 * |
|
251 * @param TAny* the object who generated the event |
|
252 * (TAny pointer to this object) |
|
253 * @since S60 v3.2.3 |
|
254 */ |
|
255 static TInt Cancel100ContinueWaitL( TAny* aParam ); |
|
256 |
|
257 private: |
|
258 |
|
259 /** |
|
260 * For performance reasons, |
|
261 * read data from the file in chunks of 640K |
|
262 * Own. |
|
263 */ |
|
264 HBufC8* iRequestBodyBuffer; |
|
265 |
|
266 /** |
|
267 * How much body data has been sent to the HTTP stack |
|
268 */ |
|
269 TUint iSendDataCount; |
|
270 |
|
271 /** |
|
272 * How much data will be sent |
|
273 */ |
|
274 TInt iOverallDataSize; |
|
275 |
|
276 /** |
|
277 * Is there still data left |
|
278 */ |
|
279 TBool iMoreToCome; |
|
280 |
|
281 /** |
|
282 * Was the process of the request already done |
|
283 * to avoid the repeated the process of the same part of the request |
|
284 */ |
|
285 TBool iAlreadyDone; |
|
286 |
|
287 /** |
|
288 * Here in file to start to read, currently always 0 |
|
289 * (the beginning of the file) |
|
290 */ |
|
291 TUint iBodyFileOffset; |
|
292 |
|
293 /** |
|
294 * Http status |
|
295 */ |
|
296 TInt iHttpStatus; |
|
297 |
|
298 /** |
|
299 * Timer to wait for 100-continue response. If no response is received |
|
300 * in the given time, we will continue with sending the body. |
|
301 * Owned. |
|
302 */ |
|
303 CPeriodic* i100ContinueTimer; |
|
304 |
|
305 /** |
|
306 * Timeout timer for current session |
|
307 */ |
|
308 CHttpNotifyTimer* iSessionTimer; |
|
309 |
|
310 }; |
|
311 |
|
312 #endif // C_HTTPUPLOADWORKER_H |