|
1 /* |
|
2 * Copyright (c) 2002-2004 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #undef _ROAP_TESTING |
|
20 |
|
21 #ifdef RD_MULTIPLE_DRIVE |
|
22 #include <DriveInfo.h> |
|
23 #endif |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "RoapResponse.h" |
|
27 #include "RoapLog.h" |
|
28 |
|
29 using namespace Roap; |
|
30 |
|
31 // EXTERNAL DATA STRUCTURES |
|
32 |
|
33 // EXTERNAL FUNCTION PROTOTYPES |
|
34 |
|
35 // CONSTANTS |
|
36 |
|
37 #ifndef RD_MULTIPLE_DRIVE |
|
38 // default filename |
|
39 _LIT( KMultipartPduTempPath, "c:\\"); |
|
40 #endif |
|
41 |
|
42 // MACROS |
|
43 |
|
44 // LOCAL CONSTANTS AND MACROS |
|
45 |
|
46 // MODULE DATA STRUCTURES |
|
47 |
|
48 // LOCAL FUNCTION PROTOTYPES |
|
49 |
|
50 // FORWARD DECLARATIONS |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CRoapResponse::CRoapResponse() |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CRoapResponse::CRoapResponse() |
|
59 { |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CRoapResponse::ConstructL() |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CRoapResponse::ConstructL() |
|
67 { |
|
68 iPdu = HBufC8::NewL( 0 ); |
|
69 iMultipartState = EOther; |
|
70 iMaxSize = -1; |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CRoapResponse::NewL() |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CRoapResponse* CRoapResponse::NewL() |
|
78 { |
|
79 CRoapResponse* self = new( ELeave ) CRoapResponse; |
|
80 CleanupStack::PushL( self ); |
|
81 self->ConstructL(); |
|
82 CleanupStack::Pop(); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CRoapResponse::~CRoapResponse() |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 CRoapResponse::~CRoapResponse() |
|
91 { |
|
92 delete iPdu; |
|
93 delete iContentName; |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CRoapResponse::ProtocolUnit() |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 const TDesC8& CRoapResponse::ProtocolUnit() const |
|
101 { |
|
102 return *iPdu; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CRoapResponse::PduFileName() |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 const TFileName& CRoapResponse::DcfFileName() const |
|
110 { |
|
111 return iDcfFileName; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CRoapResponse::SetPduFileName() |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CRoapResponse::SetDcfPathL( |
|
119 const TPath& aPath ) |
|
120 { |
|
121 LOG( _L("CRoapResponse::SetDcfPathL->") ); |
|
122 |
|
123 RFs fs; |
|
124 RFile file; |
|
125 User::LeaveIfError( fs.Connect() ); |
|
126 CleanupClosePushL( fs ); |
|
127 |
|
128 if ( aPath.Length() > 3 ) |
|
129 { |
|
130 User::LeaveIfError( file.Temp( fs, aPath, iDcfFileName, |
|
131 EFileShareExclusive | EFileWrite ) ); |
|
132 } |
|
133 else |
|
134 { |
|
135 |
|
136 #ifndef RD_MULTIPLE_DRIVE |
|
137 |
|
138 User::LeaveIfError( file.Temp( fs, KMultipartPduTempPath(), iDcfFileName, |
|
139 EFileShareExclusive | EFileWrite ) ); |
|
140 |
|
141 #else //RD_MULTIPLE_DRIVE |
|
142 |
|
143 _LIT( KDriveRoot, "%c:\\"); |
|
144 TInt driveNumber( -1 ); |
|
145 TChar driveLetter; |
|
146 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
147 fs.DriveToChar( driveNumber, driveLetter ); |
|
148 |
|
149 TFileName multipartTemp; |
|
150 multipartTemp.Format( KDriveRoot, (TUint)driveLetter ); |
|
151 |
|
152 User::LeaveIfError( file.Temp( fs, multipartTemp, iDcfFileName, |
|
153 EFileShareExclusive | EFileWrite ) ); |
|
154 |
|
155 #endif |
|
156 } |
|
157 LOG2( _L("iDcfFileName: %S"), &iDcfFileName ); |
|
158 |
|
159 file.Close(); |
|
160 CleanupStack::PopAndDestroy(); |
|
161 LOG( _L("CRoapResponse::SetDcfFileName <-") ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CRoapResponse::AppendPduFileDataL() |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CRoapResponse::AppendMultipartDataL( |
|
169 const TDesC8& aData ) |
|
170 { |
|
171 WriteL( aData ); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CRoapResponse::DataType() |
|
176 // --------------------------------------------------------- |
|
177 // |
|
178 const TDataType& CRoapResponse::DataType() const |
|
179 { |
|
180 return iDataType; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CRoapResponse::HandleBodyDataL |
|
185 // |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CRoapResponse::HandleBodyDataL( |
|
189 const TDesC8& aData) |
|
190 { |
|
191 LOG( _L("CRoapResponse::HandleBodyDataL ->") ); |
|
192 if ( iMultipartState == ERights ) |
|
193 { |
|
194 LOG( _L(" saving RO data") ); |
|
195 iPdu = iPdu->ReAlloc( iPdu->Size() + aData.Size() ); |
|
196 User::LeaveIfNull( iPdu ); |
|
197 iPdu->Des().Append( aData ); |
|
198 } |
|
199 else if ( iMultipartState == EDcf ) |
|
200 { |
|
201 RFs fs; |
|
202 RFile file; |
|
203 |
|
204 LOG( _L(" saving DCF data") ); |
|
205 User::LeaveIfError( fs.Connect() ); |
|
206 CleanupClosePushL( fs ); |
|
207 User::LeaveIfError( file.Open( fs, iDcfFileName, |
|
208 EFileShareExclusive | EFileWrite ) ); |
|
209 CleanupClosePushL( file ); |
|
210 User::LeaveIfError( file.Write( KMaxTInt32, aData ) ); |
|
211 CleanupStack::PopAndDestroy( 2 ); // file, fs |
|
212 } |
|
213 LOG( _L("CRoapResponse::HandleBodyDataL <-") ); |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CRoapResponse::StartBodyPartL |
|
218 // |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CRoapResponse::StartBodyPartL() |
|
222 { |
|
223 LOG( _L("CRoapResponse::StartBodyPartL ->") ); |
|
224 if ( iMultipartState == EOther ) |
|
225 { |
|
226 LOG( _L(" starting RO part") ); |
|
227 iMultipartState = ERights; |
|
228 } |
|
229 else if ( iMultipartState == ERights ) |
|
230 { |
|
231 LOG( _L(" starting DCF part") ); |
|
232 iMultipartState = EDcf; |
|
233 } |
|
234 else |
|
235 { |
|
236 LOG( _L(" some other part") ); |
|
237 } |
|
238 LOG( _L("CRoapResponse::StartBodyPartL <-") ); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CRoapResponse::EndBodyPartL |
|
243 // |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CRoapResponse::EndBodyPartL() |
|
247 { |
|
248 LOG( _L("CRoapResponse::EndBodyPartL ->") ); |
|
249 LOG( _L("CRoapResponse::EndBodyPartL <-") ); |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CRoapResponse::SetContentNameL |
|
254 // |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CRoapResponse::SetContentNameL( const TDes& aName ) |
|
258 { |
|
259 LOG( _L("CRoapResponse::SetContentNameL") ); |
|
260 |
|
261 delete iContentName; |
|
262 iContentName = NULL; |
|
263 |
|
264 iContentName = aName.AllocL(); |
|
265 } |
|
266 |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CRoapResponse::GetContentNameLC |
|
270 // |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CRoapResponse::GetContentNameLC( HBufC*& aName ) const |
|
274 { |
|
275 LOG( _L("CRoapResponse::GetContentName") ); |
|
276 |
|
277 if ( iContentName ) |
|
278 aName = iContentName->AllocLC(); |
|
279 else |
|
280 aName = NULL; |
|
281 } |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CRoapResponse::SetMaxSize |
|
284 // |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CRoapResponse::SetMaxSize( const TInt& aSize ) |
|
288 { |
|
289 LOG( _L("CRoapResponse::SetMaxSize") ); |
|
290 |
|
291 iMaxSize = aSize; |
|
292 } |
|
293 |
|
294 |
|
295 // ----------------------------------------------------------------------------- |
|
296 // CRoapResponse::MaxSize |
|
297 // |
|
298 // ----------------------------------------------------------------------------- |
|
299 // |
|
300 TInt CRoapResponse::MaxSize() const |
|
301 { |
|
302 LOG( _L("CRoapResponse::MaxSize") ); |
|
303 |
|
304 return iMaxSize; |
|
305 } |