|
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: HTTPBuffer is used to buffer incoming HTTP messages. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CUPNPHTTPBUFFER_H |
|
20 #define C_CUPNPHTTPBUFFER_H |
|
21 |
|
22 // INCLUDES |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <in_sock.h> |
|
26 #include "upnplist.h" |
|
27 #include "upnphttpmessage.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CUpnpHttpSession; |
|
31 class CUpnpHttpFileAccess; |
|
32 class CUpnpHttpChunkParser; |
|
33 |
|
34 // CONSTANTS |
|
35 |
|
36 // CLASS DECLARATION |
|
37 |
|
38 /** |
|
39 * @brief HTTPBuffer is used to buffer incoming HTTP messages. |
|
40 * @since Series60 2.6 |
|
41 */ |
|
42 NONSHARABLE_CLASS (CUpnpHttpBuffer) : public CBase |
|
43 { |
|
44 public: // Constructor and destructor |
|
45 /** |
|
46 * Constructor function. |
|
47 * @since Series60 2.6 |
|
48 * @param aSession Pointer to session that owns this buffer. |
|
49 * @param aToBeSavedInFile ETrue, if incoming content should be saved |
|
50 * in a file, EFalse otherwise. |
|
51 * @return A new CUpnpHttpBuffer instance |
|
52 **/ |
|
53 static CUpnpHttpBuffer* NewL( CUpnpHttpSession* aSession,TBool aToBeSavedInFile ); |
|
54 |
|
55 /** |
|
56 * Virtual destructor function. |
|
57 **/ |
|
58 virtual ~CUpnpHttpBuffer(); |
|
59 |
|
60 public: // New funtions |
|
61 |
|
62 /** |
|
63 * This function appends the aBuffer data at the end of this HTTPBuffer. |
|
64 * @since Series60 2.6 |
|
65 * @param aBuffer Buffer to append after current data. |
|
66 * @param aToBeSavedInFile. |
|
67 **/ |
|
68 |
|
69 TInt AppendL( TDesC8& aBuffer, TBool aToBeSavedInFile ); |
|
70 /** |
|
71 * This function appends only headers from the aBuffer at the end of this HTTPBuffer. |
|
72 * @since Series60 2.6 |
|
73 * @param aBuffer Buffer to append after current data. |
|
74 * @param aToBeSavedInFile. |
|
75 * @return position of double line feed |
|
76 **/ |
|
77 TInt AppendHeadersL( TDesC8& aBuffer, TBool aToBeSavedInFile ); |
|
78 |
|
79 /** |
|
80 * Decodes chunked messages. |
|
81 * @since Series60 2.6 |
|
82 **/ |
|
83 TInt ParseL( TDesC8& aBuffer ); |
|
84 |
|
85 /** |
|
86 * Returns ETrue, if buffer is ready to be converted to HTTPMessage, |
|
87 * else returns EFalse. |
|
88 * @since Series60 2.6 |
|
89 * @return ETrue, if message is ready; EFalse otherwise. |
|
90 **/ |
|
91 TBool IsReadyL(); |
|
92 |
|
93 /** |
|
94 * Returns ETrue, if header part of HTTPMessage is ready, else returns |
|
95 * EFalse. |
|
96 * @since Series60 2.6 |
|
97 * @return ETrue, if header ready; EFalse otherwise. |
|
98 **/ |
|
99 TBool IsHeaderReady(); |
|
100 |
|
101 /** |
|
102 * Returns ETrue, if body part of HTTPMessage is ready, else returns EFalse. |
|
103 * @since Series60 2.6 |
|
104 * @return ETrue, if body ready; EFalse otherwise. |
|
105 **/ |
|
106 TBool IsBodyReadyL(); |
|
107 |
|
108 /** |
|
109 * Returns the length of entire buffer. |
|
110 * @since Series60 2.6 |
|
111 * @return Length of buffer. |
|
112 **/ |
|
113 TInt BytesInBuffer(); |
|
114 |
|
115 /** |
|
116 * This function deletes aLength bytes from the beginning of HTTPBuffer. |
|
117 * @since Series60 2.6 |
|
118 * @param aLength Number of bytes to remove. |
|
119 **/ |
|
120 void RemoveL( TInt aLength ); |
|
121 |
|
122 /** |
|
123 * Returns ETrue, if chunk encoded message is finished. |
|
124 * @since Series60 2.6 |
|
125 * @return ETrue, if message is ready; EFalse otherwise. |
|
126 */ |
|
127 TBool ChunkTransferFinished(); |
|
128 |
|
129 /** |
|
130 * Returns ETrue, if message has body, else returns EFalse. |
|
131 * @since Series60 2.6 |
|
132 * @return ETrue, if message has body; EFalse otherwise. |
|
133 **/ |
|
134 TBool HasBody(); |
|
135 |
|
136 /** |
|
137 * Returns ETrue, if message's header contains |
|
138 * "Transfer-encoding: Chunked" header. |
|
139 * @since Series60 2.6 |
|
140 * @return ETrue, if message's header contains |
|
141 * "Transfer-encoding: Chunked" -header; EFalse otherwise. |
|
142 **/ |
|
143 TBool IsChunked(); |
|
144 |
|
145 /** |
|
146 * Returns Headers of the first message in the buffer. |
|
147 * @since Series60 2.6 |
|
148 * @return Message headers. |
|
149 **/ |
|
150 TPtrC8 Headers(); |
|
151 |
|
152 /** |
|
153 * Returns the content of buffer. |
|
154 * @since Series60 2.6 |
|
155 * @return Message body. |
|
156 **/ |
|
157 TPtrC8 Content(); |
|
158 |
|
159 /** |
|
160 * Returns the content length of first message in the buffer. |
|
161 * @since Series60 2.6 |
|
162 * @return Length of message. |
|
163 * @leave KErrOverflow if Content-Length > 2^32 |
|
164 **/ |
|
165 TInt ContentLengthL(); |
|
166 |
|
167 /** |
|
168 * Returns ETrue, if message's header contains "Connection: close" -header. |
|
169 * @since Series60 2.6 |
|
170 * @return ETrue, if message's header contains "Connection: close" -header; |
|
171 * EFalse otherwise. |
|
172 **/ |
|
173 TBool UsesConnectionClose(); |
|
174 |
|
175 /** |
|
176 * Returns the error code of message in buffer. |
|
177 * @param aBuffer Buffer to check the error code (buffer that contains the) |
|
178 * HTTP message). |
|
179 * @since Series60 2.6 |
|
180 **/ |
|
181 TInt MessageErrorCode( TDesC8& aBuffer ); |
|
182 |
|
183 /** |
|
184 * Returns the method (GET, POST ...) of message in buffer. |
|
185 * @since Series60 2.6 |
|
186 **/ |
|
187 TPtrC8 Method(); |
|
188 |
|
189 /** |
|
190 * Returns the method target of message in buffer. |
|
191 * Target in this context means the url of message (like in GET / HTTP/1.1 the middle part) |
|
192 * @since Series60 2.6 |
|
193 **/ |
|
194 TPtrC8 Target(); |
|
195 |
|
196 /** |
|
197 * Returns True if message content is going to be saved in file. |
|
198 * @since Series60 2.6 |
|
199 * @return ETrue if message content will be saved in file, EFalse if not. |
|
200 */ |
|
201 TBool IsToFile(); |
|
202 |
|
203 /** |
|
204 * Sets if body of message contained in buffer should be saved in file. |
|
205 * @since Series60 2.6 |
|
206 * @param aToFile - should message content be saved in file. |
|
207 */ |
|
208 void SetToFile( TBool aToFile ); |
|
209 |
|
210 |
|
211 private: // Constructors |
|
212 |
|
213 /** |
|
214 * First phase constructor. |
|
215 * @param aSession Handle to session that owns CUpnpHttpBuffer instance. |
|
216 * @param aToBeSaveInFile Should content be saved to the file. |
|
217 **/ |
|
218 CUpnpHttpBuffer( CUpnpHttpSession* aSession, TBool aToBeSavedInFile ); |
|
219 |
|
220 /** |
|
221 * By default Symbian 2nd phase constructor is private |
|
222 */ |
|
223 void ConstructL(); |
|
224 |
|
225 /** |
|
226 * Parse - decodes chunked-encoding |
|
227 * @since S60 3.2 |
|
228 * @param buffer |
|
229 * @param position in the buffer |
|
230 * @return error code |
|
231 */ |
|
232 TInt Parse( TDes8& aBuffer, TInt& aPos ); |
|
233 |
|
234 protected: |
|
235 |
|
236 // Buffer that contains the messages, owned |
|
237 RBuf8 iBuffer; |
|
238 |
|
239 // ETrue if message has content-type -header, EFalse otherwise, owned |
|
240 TBool iHasContentType; |
|
241 |
|
242 // ETrue, if content of message should be saved to a file; EFalse otherwise, owned |
|
243 TBool iToFile; |
|
244 |
|
245 // Pointer to the session that owns this CUpnpHttpFileAccess, owned |
|
246 CUpnpHttpSession* iSession; |
|
247 |
|
248 // If message is not chunked, contains the current length of message, owned |
|
249 TInt iContentLengthCounter; |
|
250 |
|
251 // If message is not chunked, contains the total length of message given |
|
252 // in Content-Length -header, owned |
|
253 TInt iContentLength; |
|
254 |
|
255 // Checking that responses with error codes ( = error code not 200) |
|
256 // are not saved to files. |
|
257 TBool iErrorCodeCheckedForSaving; |
|
258 |
|
259 // ETrue, if it is allowed to save given buffer to file |
|
260 // EFalse if it is not allowed (HTTP error other than 200). |
|
261 TBool iOkToSaveToFile; |
|
262 |
|
263 TInt iFileReadBufferSize; |
|
264 |
|
265 // Position in buffer |
|
266 TInt iPos; |
|
267 |
|
268 // Chunk parser |
|
269 CUpnpHttpChunkParser *iChunkParser; |
|
270 }; |
|
271 |
|
272 #endif // C_CUPNPHTTPBUFFER_H |
|
273 |
|
274 // End Of File |