|
1 /* |
|
2 * Copyright (c) 2009-2010 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 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * Contributors: |
|
11 * |
|
12 * Description: |
|
13 * MSRP Implementation |
|
14 * |
|
15 */ |
|
16 |
|
17 // CLASS HEADER |
|
18 #include "CMsrpMessage.h" |
|
19 |
|
20 // EXTERNAL INCLUDES |
|
21 #include <MsrpStrConsts.h> |
|
22 |
|
23 // INTERNAL INCLUDES |
|
24 #include "MsrpCommon.h" |
|
25 #include "CMSRPFromPathHeader.h" |
|
26 #include "CMSRPToPathHeader.h" |
|
27 #include "CMSRPMessageIdHeader.h" |
|
28 #include "CMSRPByteRangeHeader.h" |
|
29 #include "CMSRPContentTypeHeader.h" |
|
30 #include "CMSRPFailureReportHeader.h" |
|
31 #include "CMSRPSuccessReportHeader.h" |
|
32 #include "TMSRPHeaderUtil.h" |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CMSRPMessage::CMSRPMessage |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 EXPORT_C CMSRPMessage::CMSRPMessage() |
|
38 { |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CMSRPMessage::~CMSRPMessage |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C CMSRPMessage::~CMSRPMessage() |
|
46 { |
|
47 delete iContentBuffer; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CMSRPMessage::SetContentL |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C void CMSRPMessage::SetContent( HBufC8* aContent ) |
|
55 { |
|
56 if( iContentBuffer ) |
|
57 { |
|
58 delete iContentBuffer; |
|
59 iContentBuffer = NULL; |
|
60 } |
|
61 iContentBuffer = aContent; |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CMSRPMessage::Content |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C const TDesC8& CMSRPMessage::Content( ) |
|
69 { |
|
70 if( iContentBuffer ) |
|
71 { |
|
72 return *iContentBuffer; |
|
73 } |
|
74 return KNullDesC8(); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CMSRPMessage::IsContent |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C TBool CMSRPMessage::IsContent( ) const |
|
82 { |
|
83 if ( iContentBuffer ) |
|
84 { |
|
85 return ETrue; |
|
86 } |
|
87 |
|
88 return EFalse; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CMSRPMessage::SetFileName |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CMSRPMessage::SetFileName( const TFileName& aFileName ) |
|
96 { |
|
97 iFileName = aFileName; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CMSRPMessage::GetFileName |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C TFileName& CMSRPMessage::GetFileName( ) |
|
105 { |
|
106 return iFileName; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CMSRPMessage::SetFileSize |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 EXPORT_C void CMSRPMessage::SetFileSize( const TInt aFileSize ) |
|
114 { |
|
115 iFileSize = aFileSize; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CMSRPMessage::GetFileSize |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C TInt CMSRPMessage::GetFileSize( ) |
|
123 { |
|
124 return iFileSize; |
|
125 } |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CMSRPMessage::InternalizeL |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C CMSRPMessage* CMSRPMessage::InternalizeL( RReadStream& aReadStream ) |
|
131 { |
|
132 CMSRPMessage* self = new (ELeave) CMSRPMessage(); |
|
133 CleanupStack::PushL( self ); |
|
134 self->DoInternalizeL( aReadStream ); |
|
135 CleanupStack::Pop( self ); |
|
136 return self; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CMSRPMessage::DoInternalizeL |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 void CMSRPMessage::DoInternalizeL( RReadStream& aReadStream ) |
|
144 { |
|
145 TUint8 dataType( 0 ); |
|
146 |
|
147 // read the identifier |
|
148 if ( aReadStream.ReadUint8L() != 100 ) |
|
149 { |
|
150 User::Leave( KErrArgument ); |
|
151 } |
|
152 |
|
153 do |
|
154 { |
|
155 dataType = aReadStream.ReadUint8L(); |
|
156 |
|
157 switch( dataType ) |
|
158 { |
|
159 case 1: // from path |
|
160 { |
|
161 iFromPath = CMSRPFromPathHeader::InternalizeValueL( aReadStream ); |
|
162 break; |
|
163 } |
|
164 case 2: // to path |
|
165 { |
|
166 iToPath = CMSRPToPathHeader::InternalizeValueL( aReadStream ); |
|
167 break; |
|
168 } |
|
169 case 3: // message id |
|
170 { |
|
171 iMessageId = CMSRPMessageIdHeader::InternalizeValueL( aReadStream ); |
|
172 break; |
|
173 } |
|
174 case 4: // byte range |
|
175 { |
|
176 iByteRange = CMSRPByteRangeHeader::InternalizeValueL( aReadStream ); |
|
177 break; |
|
178 } |
|
179 case 5: // content type |
|
180 { |
|
181 iContentType = CMSRPContentTypeHeader::InternalizeValueL( aReadStream ); |
|
182 break; |
|
183 } |
|
184 case 6: // failure report |
|
185 { |
|
186 iFailureReport = CMSRPFailureReportHeader::InternalizeValueL( aReadStream ); |
|
187 break; |
|
188 } |
|
189 case 7: // success report |
|
190 { |
|
191 iSuccessReport = CMSRPSuccessReportHeader::InternalizeValueL( aReadStream ); |
|
192 break; |
|
193 } |
|
194 case 10: // content buffer |
|
195 { |
|
196 TUint32 contentLength = aReadStream.ReadUint32L(); |
|
197 iContentBuffer = HBufC8::NewL( contentLength ); |
|
198 TPtr8 bufferPtr = iContentBuffer->Des(); |
|
199 aReadStream.ReadL( bufferPtr, contentLength ); |
|
200 break; |
|
201 } |
|
202 case 11: //filename |
|
203 { |
|
204 TUint32 nameLength = aReadStream.ReadUint32L(); |
|
205 aReadStream.ReadL( iFileName, nameLength ); |
|
206 break; |
|
207 } |
|
208 case 12: //filesize |
|
209 { |
|
210 TUint32 val = aReadStream.ReadUint32L(); |
|
211 if( val > 0 ) |
|
212 { |
|
213 HBufC8* tempString = HBufC8::NewLC( val ); |
|
214 TPtr8 tempValue( tempString->Des() ); |
|
215 aReadStream.ReadL( tempValue, val ); |
|
216 iFileSize = TMSRPHeaderUtil::ConvertToNumber( tempString->Des() ); |
|
217 CleanupStack::PopAndDestroy( tempString ); |
|
218 } |
|
219 break; |
|
220 } |
|
221 case 13: //granularity |
|
222 { |
|
223 TUint32 val = aReadStream.ReadUint32L(); |
|
224 if( val > 0 ) |
|
225 { |
|
226 HBufC8* tempString = HBufC8::NewLC( val ); |
|
227 TPtr8 tempValue( tempString->Des() ); |
|
228 aReadStream.ReadL( tempValue, val ); |
|
229 iNotifyProgress = TMSRPHeaderUtil::ConvertToNumber( tempString->Des() ); |
|
230 CleanupStack::PopAndDestroy( tempString ); |
|
231 } |
|
232 break; |
|
233 } |
|
234 default: |
|
235 { |
|
236 // nothing to do |
|
237 break; |
|
238 } |
|
239 } |
|
240 |
|
241 } while( dataType ); |
|
242 } |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CMSRPMessage::ExternalizeL |
|
245 // ----------------------------------------------------------------------------- |
|
246 // |
|
247 |
|
248 EXPORT_C void CMSRPMessage::ExternalizeL( RWriteStream& aWriteStream ) |
|
249 { |
|
250 // first add the MSRP Message identifier |
|
251 aWriteStream.WriteUint8L( 100 ); // MSRP Message identifier |
|
252 |
|
253 if( iFromPath ) |
|
254 { |
|
255 aWriteStream.WriteUint8L(1); // more headers in the stream flag |
|
256 iFromPath->ExternalizeValueL( aWriteStream ); |
|
257 } |
|
258 if( iToPath ) |
|
259 { |
|
260 aWriteStream.WriteUint8L(2); // more headers in the stream flag |
|
261 iToPath->ExternalizeValueL( aWriteStream ); |
|
262 } |
|
263 if ( iMessageId ) |
|
264 { |
|
265 aWriteStream.WriteUint8L(3); // more headers in the stream flag |
|
266 iMessageId->ExternalizeValueL( aWriteStream ); |
|
267 } |
|
268 if( iByteRange ) |
|
269 { |
|
270 aWriteStream.WriteUint8L(4); // more headers in the stream flag |
|
271 iByteRange->ExternalizeValueL( aWriteStream ); |
|
272 } |
|
273 if( iContentType ) |
|
274 { |
|
275 aWriteStream.WriteUint8L(5); // more headers in the stream flag |
|
276 iContentType->ExternalizeValueL( aWriteStream ); |
|
277 } |
|
278 if( iFailureReport ) |
|
279 { |
|
280 aWriteStream.WriteUint8L(6); // more headers in the stream flag |
|
281 iFailureReport->ExternalizeValueL( aWriteStream ); |
|
282 } |
|
283 if( iSuccessReport ) |
|
284 { |
|
285 aWriteStream.WriteUint8L(7); // more headers in the stream flag |
|
286 iSuccessReport->ExternalizeValueL( aWriteStream ); |
|
287 } |
|
288 if ( IsContent() ) |
|
289 { |
|
290 aWriteStream.WriteUint8L( 10 ); |
|
291 aWriteStream.WriteInt32L( iContentBuffer->Length() ); |
|
292 aWriteStream.WriteL( *iContentBuffer, iContentBuffer->Length() ); |
|
293 } |
|
294 if ( IsFile() ) |
|
295 { |
|
296 aWriteStream.WriteUint8L( 11 ); // 2 = file ID |
|
297 aWriteStream.WriteInt32L( iFileName.Length() ); |
|
298 aWriteStream.WriteL( iFileName ); |
|
299 } |
|
300 |
|
301 if( iFileSize > 0 ) |
|
302 { |
|
303 aWriteStream.WriteUint8L( 12 ); |
|
304 TBuf8< 50 > val; |
|
305 val.AppendNum( iFileSize ); |
|
306 aWriteStream.WriteInt32L( val.Length() ); |
|
307 aWriteStream.WriteL( val ); |
|
308 } |
|
309 if( iNotifyProgress > 0 ) |
|
310 { |
|
311 aWriteStream.WriteUint8L( 13 ); |
|
312 TBuf8< 50 > val; |
|
313 val.AppendNum( iNotifyProgress ); |
|
314 aWriteStream.WriteInt32L( val.Length() ); |
|
315 aWriteStream.WriteL( val ); |
|
316 } |
|
317 aWriteStream.WriteUint8L(0); // no more headers in the stream flag |
|
318 } |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // CMSRPMessage::IsMessage |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TBool CMSRPMessage::IsMessage( const TDesC8& aBuffer ) |
|
325 { |
|
326 if ( aBuffer.Length() ) |
|
327 { |
|
328 if ( aBuffer[ 0 ] == 100 ) |
|
329 { |
|
330 return ETrue; |
|
331 } |
|
332 } |
|
333 |
|
334 return EFalse; |
|
335 } |
|
336 |
|
337 EXPORT_C TBool CMSRPMessage::IsFile() |
|
338 { |
|
339 if ( iFileName.Length() ) |
|
340 { |
|
341 return ETrue; |
|
342 } |
|
343 return EFalse; |
|
344 |
|
345 } |
|
346 |
|
347 |
|
348 EXPORT_C void CMSRPMessage::SetNotifyProgress(TBool aNotify) |
|
349 { |
|
350 iNotifyProgress = aNotify; |
|
351 } |
|
352 |
|
353 EXPORT_C TBool CMSRPMessage::GetNotifyProgress() |
|
354 { |
|
355 return iNotifyProgress; |
|
356 } |
|
357 // End of File |