|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: UpnpHttpFileAccess is a class responsible for serving |
|
15 * requested files to upload as well as for saving file that are |
|
16 * being downladed. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #ifndef C_CUPNPHTTPFILEACCESS_H |
|
22 #define C_CUPNPHTTPFILEACCESS_H |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include <e32base.h> |
|
27 #include <f32file.h> |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CUpnpHttpSession; |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 /** |
|
35 * @brief CUpnpHttpFileAccess is used to send and receive files in Httpserver |
|
36 * and Httpsession. |
|
37 * @since Series60 2.6 |
|
38 */ |
|
39 NONSHARABLE_CLASS (CUpnpHttpFileAccess) : public CBase |
|
40 { |
|
41 public: // Constructors and destructor |
|
42 |
|
43 /** |
|
44 * Constructor function. This constructor is used when file is served by |
|
45 * HttpServer. |
|
46 * @since Series60 2.6 |
|
47 * @param aSession Pointer to owning session of this CUpnpHttpFileAccess. |
|
48 * @param aHeaderBuffer Buffer that contains the headers of message to |
|
49 * be served. |
|
50 * @param aFilename Name of file to be served. |
|
51 * @param aFileSize Size of file to be served. |
|
52 * @return A new CUpnpHttpFileAccess instance. |
|
53 **/ |
|
54 static CUpnpHttpFileAccess* NewL( CUpnpHttpSession* aSession, |
|
55 const TDesC8& aHeaderBuffer, |
|
56 const TDesC16& aFilename, |
|
57 TInt aFileSize ); |
|
58 |
|
59 /** |
|
60 * Constructor function. This constructor is used when file is to be received. |
|
61 * @since Series60 2.6 |
|
62 * @param aSession Pointer to owning session of this CUpnpHttpFileAccess. |
|
63 * @param aFilename Name of file to be saved locally. |
|
64 * @param aHandle the thread log handle. |
|
65 * @return A new CUpnpHttpFileAccess instance. |
|
66 **/ |
|
67 static CUpnpHttpFileAccess* NewL( CUpnpHttpSession* aSession, |
|
68 const TDesC16& aFilename ); |
|
69 |
|
70 /** |
|
71 * Virtual Destructor function. |
|
72 **/ |
|
73 ~CUpnpHttpFileAccess(); |
|
74 |
|
75 public: // New functions |
|
76 |
|
77 /** |
|
78 * Returns the number of bytes that has been transferred |
|
79 * @since Series60 2.6 |
|
80 * @return Number of bytes that has been transferred. |
|
81 **/ |
|
82 TInt TransferredBytes(); |
|
83 |
|
84 /** |
|
85 * Returns the number of bytes that is to be transferred, ie size of file. |
|
86 * @since Series60 2.6 |
|
87 * @return Number of bytes to be transferred. |
|
88 **/ |
|
89 TInt TransferTotal(); |
|
90 /** |
|
91 * Sets the reading position of the file. |
|
92 * @since Series60 2.6 |
|
93 * @param aNewPos Position of reading, counting from start of file. |
|
94 **/ |
|
95 void SetPosOfFile( TUint aNewPos ); |
|
96 |
|
97 /** |
|
98 * Returns the reading position of the file. |
|
99 * @since Series60 2.6 |
|
100 * @return Position of reading, counting from start of file. |
|
101 **/ |
|
102 TUint PosOfFile(); |
|
103 |
|
104 /** |
|
105 * Sets the offset of the local file at which should be downloaded content saved. |
|
106 * @since Series60 2.6 |
|
107 * @param aNewPos Offset of the local file from the start of the file. |
|
108 **/ |
|
109 void SetOffset( TUint aOffset ); |
|
110 |
|
111 /** |
|
112 * Sets the position where to stop reading the file. |
|
113 * @since Series60 2.6 |
|
114 * @param aNewPos position where to stop reading the file, counting from start of file. |
|
115 **/ |
|
116 void SetEndPosOfFile( TInt aNewEndPos ); |
|
117 |
|
118 /** |
|
119 * Returns the position where to stop reading the file. |
|
120 * @since Series60 2.6 |
|
121 * @return position where to stop reading the file, counting from start of file. |
|
122 **/ |
|
123 TInt EndPosOfFile(); |
|
124 |
|
125 /** |
|
126 * Sets the reading position of the headerbuffer. |
|
127 * @since Series60 2.6 |
|
128 * @param aNewPos Position of reading, counting from start of headerbuffer. |
|
129 */ |
|
130 void SetPosOfHeader( TUint aNewPos ); |
|
131 |
|
132 /** |
|
133 * Returns the filename of the served file. |
|
134 * @since Series60 2.6 |
|
135 * @return Name of file. |
|
136 **/ |
|
137 TDesC16& FileToServe(); |
|
138 |
|
139 |
|
140 /** |
|
141 * Gets bytes to be sent |
|
142 * @since Series60 3.2 |
|
143 * @param aPointer to write the read content |
|
144 * @param aBytesToSend Number of bytes to send. |
|
145 * @return ETrue, if transfer is finished; EFalse otherwise. |
|
146 **/ |
|
147 TBool GetL( TPtr8& aPointer, TInt aBytesToSend ); |
|
148 |
|
149 /** |
|
150 * Saves aBuffer at the end of file used in this CUpnpHttpFileAccess. |
|
151 * @since Series60 3.2 |
|
152 * @param aBuffer Content to save (append) to file. |
|
153 * @return error code |
|
154 **/ |
|
155 TInt SaveL( TDesC8& aBuffer ); |
|
156 |
|
157 /** |
|
158 * Sets the total size of file transfer (FileSize). |
|
159 * @since Series60 2.6 |
|
160 **/ |
|
161 void SetTotalSize( TInt aSizeToSet ); |
|
162 |
|
163 /** |
|
164 * Deletes file in error cases. |
|
165 * @since Series60 2.6 |
|
166 **/ |
|
167 void DeleteFile(); |
|
168 |
|
169 /** |
|
170 * Returnes if currently handled file is downloaded or uploaded. |
|
171 * @since Series60 2.6 |
|
172 * @return if currently handled file is downloaded or uploaded. |
|
173 **/ |
|
174 TBool Download(); |
|
175 |
|
176 /** |
|
177 * Returnes true if currently handled file is not removed. |
|
178 * @since Series60 3.2 |
|
179 * @return TRUE if processed file exist. |
|
180 **/ |
|
181 TBool FileExist(); |
|
182 |
|
183 /** |
|
184 * Returnes the number of bytes written |
|
185 * @since Series60 3.2 |
|
186 * @return TInt |
|
187 **/ |
|
188 TInt BytesWritten(); |
|
189 |
|
190 /** |
|
191 * Sets the encoding mode |
|
192 * @param TBool |
|
193 * @since Series60 3.2 |
|
194 **/ |
|
195 void SetEncodingMode(TBool aIsChunked); |
|
196 |
|
197 /** |
|
198 * Returns the encoding mode |
|
199 * @since Series60 3.2 |
|
200 * @return ETrue if chunked-encoded |
|
201 **/ |
|
202 TBool EncodingMode(); |
|
203 |
|
204 /** |
|
205 * Sets the size of the transfer |
|
206 * @since Series60 3.2 |
|
207 * @param TInt |
|
208 **/ |
|
209 void SetTransferTotal(TInt aLength); |
|
210 |
|
211 /** |
|
212 * Gets the headers of content to be sent |
|
213 * @since Series60 3.2 |
|
214 * @param TInt |
|
215 **/ |
|
216 const TDesC8& GetHeaders(); |
|
217 |
|
218 /** |
|
219 * Called after headers were queued to be sent |
|
220 * @since Series60 3.2 |
|
221 **/ |
|
222 void SetHeadersSent(); |
|
223 |
|
224 /** |
|
225 * True if HTTP headers sent |
|
226 * @since Series60 3.2 |
|
227 **/ |
|
228 TBool HeadersSent(); |
|
229 |
|
230 /** |
|
231 * True when chunk tranfer completes |
|
232 * @since Series60 3.2 |
|
233 **/ |
|
234 void SetChunkCompleted( TBool aCompleted ); |
|
235 |
|
236 private: // Constructors |
|
237 |
|
238 /** |
|
239 * First phase constructor. This constructor is used when file is to be |
|
240 * sent from HttpServer. |
|
241 * @since Series60 2.6 |
|
242 * @param aFileSize Size of file to be served. |
|
243 **/ |
|
244 CUpnpHttpFileAccess( TInt aFileSize ); |
|
245 |
|
246 /** |
|
247 * First phase constructor. This constructor is used when file is to |
|
248 * be received. |
|
249 * @since Series60 2.6 |
|
250 **/ |
|
251 CUpnpHttpFileAccess(); |
|
252 |
|
253 /** |
|
254 * By default Symbian 2nd phase constructor is private. |
|
255 * @param aSession handle to parent session that owns this object. |
|
256 * @param aHeaderBuffer descriptor with message headers. |
|
257 * @param aFileName file name of the file to serve. |
|
258 */ |
|
259 void ConstructL( CUpnpHttpSession* aSession, |
|
260 const TDesC8& aHeaderBuffer, |
|
261 const TDesC16& aFilename ); |
|
262 |
|
263 /** |
|
264 * By default Symbian 2nd phase constructor is private. |
|
265 * @param aSession handle to parent session that owns this object. |
|
266 * @param aFileName file name of the file in which the incoming content is saved. |
|
267 */ |
|
268 void ConstructL( CUpnpHttpSession* aSession, const TDesC16& aFilename ); |
|
269 |
|
270 /** |
|
271 * Checks if whole file has been read - returns ETrue if yes |
|
272 * Close iTargetFile when returns ETrue |
|
273 */ |
|
274 TBool IsEndOfFile(); |
|
275 |
|
276 private: // Data |
|
277 |
|
278 // Total Size of downloaded file, owned |
|
279 TInt iTotalSizeOfDownload; |
|
280 |
|
281 // Buffer that contains the headers of served message owned |
|
282 HBufC8* iHeaderBuffer; |
|
283 |
|
284 // Name of served file, owned |
|
285 HBufC16* iFileToServe; |
|
286 |
|
287 // Position to read or write file, owned |
|
288 TInt iPosInFile; |
|
289 |
|
290 // Position to stop read file at, owned |
|
291 TInt iEndPosOfFile; |
|
292 |
|
293 // Total Size of served file, owned |
|
294 TInt iSizeOfFile; |
|
295 |
|
296 // Position to read or write headerbuffer, owned |
|
297 TInt iPosToReadHeader; |
|
298 |
|
299 // Length of headers, owned |
|
300 TInt iHeaderLength; |
|
301 |
|
302 // Pointer to owning session, owned |
|
303 CUpnpHttpSession* iSession; |
|
304 |
|
305 // ETrue, if headers has been sent; EFalse otherwise, owned |
|
306 TBool iHeadersSent; |
|
307 |
|
308 // FileServer handle that is used to hold iFile open, owned |
|
309 RFs iFsSession; |
|
310 |
|
311 // File handle that is used for downloading and locking the |
|
312 // active file, owned |
|
313 RFile iFile; |
|
314 |
|
315 // Boolean to detect if it is download or upload, owned |
|
316 TBool iIsDownload; |
|
317 |
|
318 RFile iTargetFile; |
|
319 TInt iOpen; |
|
320 HBufC* iOpenedFile; |
|
321 //bytes already written |
|
322 TInt iBytesWritten; |
|
323 //if data is chunked |
|
324 TBool iIsChunked; |
|
325 //if chunk transfer is completed |
|
326 TBool iIsChunkCompleted; |
|
327 //activated when resource closed and deleted |
|
328 TBool iIsDeleted; |
|
329 }; |
|
330 |
|
331 #endif //C_CUPNPHTTPFILEACCESS_H |
|
332 |
|
333 // End Of File |