|
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: Parses chunked-encoding content. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CUPNPHTTPCHUNKPARSER_H |
|
20 #define C_CUPNPHTTPCHUNKPARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <f32file.h> |
|
25 |
|
26 // FORWARD DECLARATIONS |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 /** |
|
31 * CUpnpHttpChunkParser: |
|
32 * Parses chunked-encoding content. |
|
33 * @lib dlnawebserver.lib |
|
34 * @since S60 3.2 |
|
35 */ |
|
36 NONSHARABLE_CLASS (CUpnpHttpChunkParser) : public CBase |
|
37 { |
|
38 public: |
|
39 //possible values of the context |
|
40 enum TChunkContext |
|
41 { |
|
42 EUnknown=0, |
|
43 EHeader, |
|
44 EBody, |
|
45 ELastChunk, |
|
46 EExtension, |
|
47 ETrailer, |
|
48 EEndChunkBody, |
|
49 EError, |
|
50 EFinish, |
|
51 }; |
|
52 |
|
53 |
|
54 // Constructor and destructor |
|
55 /** |
|
56 * Constructor function. |
|
57 * @since Series60 3.2 |
|
58 * @return A new CUpnpHttpChunkParser instance |
|
59 **/ |
|
60 static CUpnpHttpChunkParser* NewL(); |
|
61 |
|
62 /** |
|
63 * Virtual destructor function. |
|
64 * @since Series60 3.2 |
|
65 **/ |
|
66 virtual ~CUpnpHttpChunkParser(); |
|
67 |
|
68 /** |
|
69 * Parse - decodes chunked-encoding |
|
70 * @since S60 3.2 |
|
71 * @param buffer |
|
72 * @param position in the buffer |
|
73 * @return error code |
|
74 */ |
|
75 TInt Parse(TDes8& aBuffer,TInt& aPos); |
|
76 |
|
77 /** |
|
78 * SetErrorState - set error state |
|
79 * @since S60 3.2 |
|
80 */ |
|
81 void SetErrorState(); |
|
82 |
|
83 /** |
|
84 * IsFinished - if decoding finished |
|
85 * @since S60 3.2 |
|
86 * @return TBool |
|
87 */ |
|
88 TBool IsFinished(); |
|
89 |
|
90 /** |
|
91 * Reset - resets parser for new decoding |
|
92 * @since S60 3.2 |
|
93 */ |
|
94 void Reset(); |
|
95 |
|
96 |
|
97 |
|
98 protected: // Constructors |
|
99 |
|
100 /** |
|
101 * First phase constructor. |
|
102 * @param aSession Handle to session that owns CUpnpChunkFileTransferBuffer instance. |
|
103 * @param aToBeSaveInFile Should content be saved to the file. |
|
104 **/ |
|
105 CUpnpHttpChunkParser(); |
|
106 |
|
107 /** |
|
108 * By default Symbian 2nd phase constructor is private |
|
109 */ |
|
110 void ConstructL(); |
|
111 |
|
112 private: |
|
113 |
|
114 /** |
|
115 * ParseBody - decodes chunk-body |
|
116 * @since S60 3.2 |
|
117 * @param buffer |
|
118 * @param position in the buffer |
|
119 * @return ETrue if all data parsed |
|
120 */ |
|
121 TBool ParseBody(TDes8& aBuffer,TInt& aPos); |
|
122 |
|
123 /** |
|
124 * ParseHeader - decodes chunk-header |
|
125 * @since S60 3.2 |
|
126 * @param buffer |
|
127 * @param position in the buffer |
|
128 * @return ETrue if all data parsed |
|
129 */ |
|
130 TBool ParseHeader(TDes8& aBuffer,TInt& aPos); |
|
131 |
|
132 /** |
|
133 * ParseExtension - decodes chunk-extension |
|
134 * @since S60 3.2 |
|
135 * @param buffer |
|
136 * @param position in the buffer |
|
137 * @return ETrue if all data parsed |
|
138 */ |
|
139 TBool ParseExtension(TDes8& aBuffer,TInt& aPos); |
|
140 |
|
141 /** |
|
142 * ParseTrailer - decodes chunk-trailer |
|
143 * @since S60 3.2 |
|
144 * @param buffer |
|
145 * @param position in the buffer |
|
146 * @return ETrue if all data parsed |
|
147 */ |
|
148 TBool ParseTrailer(TDes8& aBuffer,TInt& aPos); |
|
149 |
|
150 /** |
|
151 * ParseLastChunk - decodes last chunk |
|
152 * @since S60 3.2 |
|
153 * @param buffer |
|
154 * @param position in the buffer |
|
155 * @return ETrue if all data parsed |
|
156 */ |
|
157 TBool ParseLastChunk(TDes8& aBuffer,TInt& aPos); |
|
158 |
|
159 /** |
|
160 * IsEmpty - checks if any data left |
|
161 * @since S60 3.2 |
|
162 * @param buffer |
|
163 * @param position in the buffer |
|
164 * @return ETrue if no data left |
|
165 */ |
|
166 TBool IsEmpty(TDes8& aBuffer,TInt aPos); |
|
167 |
|
168 protected: |
|
169 |
|
170 //Context of the parser |
|
171 TChunkContext iContext; |
|
172 //size of the current chunk |
|
173 TInt iChunkSize; |
|
174 //error in parsing |
|
175 TInt iError; |
|
176 //already appended bytes of the current chunk |
|
177 TInt iBytesAppended; |
|
178 |
|
179 }; |
|
180 |
|
181 #endif // C_CUPNPHTTPCHUNKPARSER_H |
|
182 |
|
183 // End Of File |