|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * Entry wrapper implementing MMmsEntry for client side. |
|
16 * Hides difference between CMscEntry and CMsvServerEntry |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 |
|
24 #include <e32std.h> |
|
25 |
|
26 #include <msventry.h> |
|
27 #include <msvstd.h> |
|
28 #include <msvapi.h> //Message Server |
|
29 #include <badesca.h> |
|
30 #include <cmsvmimeheaders.h> |
|
31 #include <mmsvattachmentmanager.h> |
|
32 #include <mmsvattachmentmanagersync.h> |
|
33 #include <centralrepository.h> |
|
34 |
|
35 #include "mmscliententry.h" |
|
36 #include "MmsEnginePrivateCRKeys.h" |
|
37 #include "mmsheaders.h" |
|
38 #include "mmsattachmenthandler.h" |
|
39 #include "mmsgenutils.h" |
|
40 |
|
41 |
|
42 // EXTERNAL DATA STRUCTURES |
|
43 |
|
44 // EXTERNAL FUNCTION PROTOTYPES |
|
45 |
|
46 // CONSTANTS |
|
47 |
|
48 // MACROS |
|
49 |
|
50 // LOCAL CONSTANTS AND MACROS |
|
51 |
|
52 // MODULE DATA STRUCTURES |
|
53 |
|
54 // LOCAL FUNCTION PROTOTYPES |
|
55 |
|
56 // ==================== LOCAL FUNCTIONS ==================== |
|
57 |
|
58 // ================= MEMBER FUNCTIONS ======================= |
|
59 |
|
60 // C++ default constructor can NOT contain any code, that |
|
61 // might leave. |
|
62 // |
|
63 CMmsClientEntry::CMmsClientEntry( RFs& aFs, CMsvEntry& aEntry ): |
|
64 iFs ( aFs ), |
|
65 iCMsvEntry ( aEntry ) |
|
66 { |
|
67 } |
|
68 |
|
69 // EPOC default constructor can leave. |
|
70 void CMmsClientEntry::ConstructL( TMsvId aServiceId ) |
|
71 { |
|
72 iServiceId = aServiceId; |
|
73 iMessageEntry = iCMsvEntry.EntryId(); |
|
74 if ( iMessageEntry == iServiceId ) |
|
75 { |
|
76 iMessageEntry = KMsvNullIndexEntryId; |
|
77 } |
|
78 iMessageDrive = iCMsvEntry.Session().CurrentDriveL(); |
|
79 |
|
80 TMmsGenUtils::GetLoggingSettings( iLogAllDecoded, iDump ); |
|
81 |
|
82 } |
|
83 |
|
84 // Two-phased constructor. |
|
85 EXPORT_C CMmsClientEntry* CMmsClientEntry::NewL( RFs& aFs, CMsvEntry& aEntry, TMsvId aServiceId ) |
|
86 { |
|
87 CMmsClientEntry* self = new (ELeave) CMmsClientEntry(aFs, aEntry ); |
|
88 |
|
89 CleanupStack::PushL( self ); |
|
90 self->ConstructL( aServiceId ); |
|
91 CleanupStack::Pop( self ); |
|
92 |
|
93 return self; |
|
94 } |
|
95 |
|
96 |
|
97 // Destructor |
|
98 CMmsClientEntry::~CMmsClientEntry() |
|
99 { |
|
100 if ( iFileOpen ) |
|
101 { |
|
102 iAttaFile.Close(); |
|
103 iFileOpen = EFalse; |
|
104 } |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------- |
|
108 // CMmsClientEntry::EditStoreL |
|
109 // --------------------------------------------------------- |
|
110 // |
|
111 CMsvStore* CMmsClientEntry::EditStoreL() |
|
112 { |
|
113 return iCMsvEntry.EditStoreL(); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------- |
|
117 // CMmsClientEntry::ReadStoreL |
|
118 // --------------------------------------------------------- |
|
119 // |
|
120 CMsvStore* CMmsClientEntry::ReadStoreL() |
|
121 { |
|
122 return iCMsvEntry.ReadStoreL(); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // CMmsClientEntry::GetIndexEntry |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 TInt CMmsClientEntry::GetIndexEntry( TMsvEntry& aTMsvEntry ) |
|
130 { |
|
131 if ( iMessageEntry == KMsvNullIndexEntryId ) |
|
132 { |
|
133 return KErrNotFound; |
|
134 } |
|
135 aTMsvEntry = iCMsvEntry.Entry(); |
|
136 return KErrNone; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------- |
|
140 // CMmsClientEntry::ChangeIndexEntry |
|
141 // --------------------------------------------------------- |
|
142 // |
|
143 TInt CMmsClientEntry::ChangeIndexEntry( TMsvEntry& aTMsvEntry ) |
|
144 { |
|
145 if ( iMessageEntry == KMsvNullIndexEntryId ) |
|
146 { |
|
147 return KErrNotFound; |
|
148 } |
|
149 TRAPD( error, iCMsvEntry.ChangeL( aTMsvEntry ) ); |
|
150 return error; |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------- |
|
154 // CMmsClientEntry::SetContext |
|
155 // --------------------------------------------------------- |
|
156 // |
|
157 TInt CMmsClientEntry::SetCurrentEntry( TMsvId aEntryId ) |
|
158 { |
|
159 if ( iMessageEntry == aEntryId && iCMsvEntry.Entry().Id() == aEntryId ) |
|
160 { |
|
161 // we already have the context |
|
162 return KErrNone; |
|
163 } |
|
164 TRAPD( error, iCMsvEntry.SetEntryL( aEntryId ) ); |
|
165 if ( error == KErrNone ) |
|
166 { |
|
167 iMessageEntry = aEntryId; |
|
168 } |
|
169 else |
|
170 { |
|
171 iMessageEntry = KMsvNullIndexEntryId; |
|
172 } |
|
173 |
|
174 return error; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CMmsClientEntry::AttachmentsSize |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 TInt CMmsClientEntry::AttachmentsSizeL( CMsvStore& aStore ) |
|
182 { |
|
183 return CMmsAttachmentHandler::AttachmentsSizeL( aStore ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // CMmsClientEntry::DiskSpaceBelowCriticalLevelL |
|
188 // --------------------------------------------------------- |
|
189 // |
|
190 TInt CMmsClientEntry::DiskSpaceBelowCriticalLevelL( TInt aDataSize ) |
|
191 { |
|
192 TInt error = KErrNone; |
|
193 |
|
194 if ( TMmsGenUtils::DiskSpaceBelowCriticalLevelL( |
|
195 &iFs, aDataSize, iMessageDrive ) ) |
|
196 { |
|
197 error = KErrDiskFull; |
|
198 } |
|
199 |
|
200 return error; |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------- |
|
204 // CMmsClientEntry:: |
|
205 // --------------------------------------------------------- |
|
206 // |
|
207 TInt CMmsClientEntry::StoreMmsHeadersL( CMmsHeaders& aMmsHeaders, CMsvStore* aStore ) |
|
208 { |
|
209 TInt error = KErrNone; |
|
210 if ( DiskSpaceBelowCriticalLevelL( aMmsHeaders.Size() ) ) |
|
211 { |
|
212 error = KErrDiskFull; |
|
213 } |
|
214 |
|
215 if ( error == KErrNone ) |
|
216 { |
|
217 CMsvStore* store = aStore; |
|
218 if ( !aStore ) |
|
219 { |
|
220 store = iCMsvEntry.EditStoreL(); |
|
221 CleanupStack::PushL( store ); |
|
222 } |
|
223 aMmsHeaders.StoreL( *store ); |
|
224 if ( !aStore ) |
|
225 { |
|
226 store->CommitL(); |
|
227 CleanupStack::PopAndDestroy( store ); |
|
228 } |
|
229 } |
|
230 |
|
231 return error; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------- |
|
235 // CMmsClientEntry:: |
|
236 // --------------------------------------------------------- |
|
237 // |
|
238 void CMmsClientEntry::RestoreMmsHeadersL( CMmsHeaders& aMmsHeaders, CMsvStore* aStore ) |
|
239 { |
|
240 // The entry must be kept pointing to the message entry |
|
241 // As all attachment are stored to the message enrty, it is |
|
242 // no longer necessary to switch the context between message |
|
243 // entry and attachment entry. |
|
244 CMsvStore* store = aStore; |
|
245 if ( !aStore ) |
|
246 { |
|
247 store = iCMsvEntry.ReadStoreL(); |
|
248 CleanupStack::PushL( store ); |
|
249 } |
|
250 aMmsHeaders.RestoreL( *store ); |
|
251 if ( !aStore ) |
|
252 { |
|
253 CleanupStack::PopAndDestroy( store ); |
|
254 } |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------- |
|
258 // CMmsClientEntry:: |
|
259 // --------------------------------------------------------- |
|
260 // |
|
261 TInt CMmsClientEntry::CreateFileAttachmentL( |
|
262 CMsvStore& aStore, |
|
263 const TDesC& aFileName, |
|
264 const TPtrC8& aAttachmentData, |
|
265 CMsvMimeHeaders& aMimeHeaders, |
|
266 TMsvAttachmentId& aAttachment, |
|
267 TInt& aAttachmentSize, |
|
268 TInt32& aDRMFlags ) |
|
269 { |
|
270 TInt error = KErrNone; |
|
271 CreateEmptyFileAttachmentL( |
|
272 aStore, |
|
273 aFileName, |
|
274 aMimeHeaders, |
|
275 aAttachment ); |
|
276 |
|
277 error = ProcessAttachmentDataL( aAttachmentData, aDRMFlags ); |
|
278 |
|
279 TInt error2 = KErrNone; |
|
280 error2 = FinalizeAttachmentL( aStore, aAttachmentSize, aDRMFlags ); |
|
281 |
|
282 if ( error == KErrNone ) |
|
283 { |
|
284 error = error2; |
|
285 } |
|
286 |
|
287 return error; |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------- |
|
291 // CMmsClientEntry:: |
|
292 // --------------------------------------------------------- |
|
293 // |
|
294 TInt CMmsClientEntry::DeleteEntry( TMsvId aEntryIndex ) |
|
295 { |
|
296 TInt error = KErrNone; |
|
297 TRAP( error, |
|
298 { |
|
299 iCMsvEntry.SetEntryL( aEntryIndex ); |
|
300 iCMsvEntry.SetEntryL( iCMsvEntry.Entry().Parent() ); |
|
301 iCMsvEntry.DeleteL( aEntryIndex ); |
|
302 } ) |
|
303 |
|
304 if ( error == KErrNotFound ) |
|
305 { |
|
306 error = KErrNone; |
|
307 } |
|
308 |
|
309 iMessageEntry = KMsvNullIndexEntryId; |
|
310 |
|
311 return error; |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------- |
|
315 // CMmsClientEntry:: |
|
316 // --------------------------------------------------------- |
|
317 // |
|
318 TBool CMmsClientEntry::IsValidFilename( |
|
319 const TPtrC& aFileName ) |
|
320 { |
|
321 return CMmsAttachmentHandler::IsValidFilename( iFs, aFileName ); |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------- |
|
325 // CMmsClientEntry:: |
|
326 // --------------------------------------------------------- |
|
327 // |
|
328 TBool CMmsClientEntry::GetDecodingFlag() |
|
329 { |
|
330 return iLogAllDecoded; |
|
331 } |
|
332 |
|
333 // --------------------------------------------------------- |
|
334 // CMmsClientEntry:: |
|
335 // --------------------------------------------------------- |
|
336 // |
|
337 TBool CMmsClientEntry::GetDumpFlag() |
|
338 { |
|
339 return iDump; |
|
340 } |
|
341 |
|
342 // --------------------------------------------------------- |
|
343 // CMmsClientEntry:: |
|
344 // --------------------------------------------------------- |
|
345 // |
|
346 void CMmsClientEntry::CreateEmptyFileAttachmentL( |
|
347 CMsvStore& aStore, |
|
348 const TDesC& aFileName, |
|
349 CMsvMimeHeaders& aMimeHeaders, |
|
350 TMsvAttachmentId& aAttachment) |
|
351 { |
|
352 |
|
353 iAttaId = 0; |
|
354 if ( iFileOpen ) |
|
355 { |
|
356 iAttaFile.Close(); |
|
357 iFileOpen = EFalse; |
|
358 } |
|
359 |
|
360 // store must be created before attachmentInfo because attachment info ownership |
|
361 // will be transferred to attachment manager |
|
362 |
|
363 CMsvAttachment* attachmentInfo = CMsvAttachment::NewL( CMsvAttachment::EMsvFile ); |
|
364 CleanupStack::PushL( attachmentInfo ); |
|
365 |
|
366 attachmentInfo->SetAttachmentNameL( aFileName ); |
|
367 // We must set size after the data has been saved |
|
368 attachmentInfo->SetComplete( ETrue ); |
|
369 |
|
370 // take type from mime headers |
|
371 HBufC8* tempContentType = HBufC8::NewL( aMimeHeaders.ContentType().Length() + |
|
372 aMimeHeaders.ContentSubType().Length() + 1 ); |
|
373 CleanupStack::PushL( tempContentType ); |
|
374 tempContentType->Des().Copy( aMimeHeaders.ContentType() ); |
|
375 tempContentType->Des().Append( KMmsSlash8 ); |
|
376 tempContentType->Des().Append( aMimeHeaders.ContentSubType() ); |
|
377 attachmentInfo->SetMimeTypeL( tempContentType->Des() ); |
|
378 CleanupStack::PopAndDestroy( tempContentType ); |
|
379 |
|
380 aMimeHeaders.StoreL( *attachmentInfo ); // Mime headers are streamed into atta info |
|
381 |
|
382 if ( DiskSpaceBelowCriticalLevelL( aMimeHeaders.Size() ) ) |
|
383 { |
|
384 // attachmentInfo ownership was not transferred - it must be destroyed |
|
385 CleanupStack::PopAndDestroy( attachmentInfo ); |
|
386 User::Leave( KErrDiskFull ); |
|
387 } |
|
388 |
|
389 MMsvAttachmentManagerSync& attaMan = aStore.AttachmentManagerExtensionsL(); |
|
390 attaMan.CreateAttachmentL( aFileName, iAttaFile, attachmentInfo ); |
|
391 CleanupStack::Pop( attachmentInfo ); // attachmentInfo ownership was transferred. |
|
392 aAttachment = attachmentInfo->Id(); |
|
393 iAttaId = aAttachment; |
|
394 iFileOpen = ETrue; |
|
395 |
|
396 } |
|
397 |
|
398 // --------------------------------------------------------- |
|
399 // CMmsClientEntry:: |
|
400 // --------------------------------------------------------- |
|
401 // |
|
402 TInt CMmsClientEntry::ProcessAttachmentDataL( |
|
403 const TPtrC8& aAttachmentData, |
|
404 TInt32& /*aDRMFlags*/ ) |
|
405 { |
|
406 if ( DiskSpaceBelowCriticalLevelL( aAttachmentData.Size() ) ) |
|
407 { |
|
408 return KErrDiskFull; |
|
409 } |
|
410 else |
|
411 { |
|
412 return iAttaFile.Write( aAttachmentData ); |
|
413 } |
|
414 } |
|
415 |
|
416 // --------------------------------------------------------- |
|
417 // CMmsClientEntry:: |
|
418 // --------------------------------------------------------- |
|
419 // |
|
420 TInt CMmsClientEntry::FinalizeAttachmentL( |
|
421 CMsvStore& aStore, |
|
422 TInt& aAttachmentSize, |
|
423 TInt32& /*aDRMFlags*/ ) |
|
424 { |
|
425 TInt error = KErrNone; |
|
426 |
|
427 TInt size = 0; |
|
428 if ( iFileOpen ) |
|
429 { |
|
430 error = iAttaFile.Flush(); |
|
431 iAttaFile.Size( size ); |
|
432 } |
|
433 aAttachmentSize = size; |
|
434 |
|
435 if ( iFileOpen ) |
|
436 { |
|
437 iAttaFile.Close(); |
|
438 iFileOpen = EFalse; |
|
439 } |
|
440 |
|
441 MMsvAttachmentManager& attaMan = aStore.AttachmentManagerL(); |
|
442 MMsvAttachmentManagerSync& attaManSync = aStore.AttachmentManagerExtensionsL(); |
|
443 |
|
444 if ( size == 0 ) |
|
445 { |
|
446 // if file was not open, open it and get the size |
|
447 RFile handle = attaMan.GetAttachmentFileL( iAttaId ); |
|
448 handle.Size( size ); |
|
449 handle.Close(); |
|
450 } |
|
451 CMsvAttachment* attachmentInfo = attaMan.GetAttachmentInfoL( iAttaId ); |
|
452 CleanupStack::PushL( attachmentInfo ); |
|
453 attachmentInfo->SetSize( size ); |
|
454 TRAPD( error2, attaManSync.ModifyAttachmentInfoL( attachmentInfo ) ); |
|
455 if ( error2 == KErrNone ) |
|
456 { |
|
457 CleanupStack::Pop( attachmentInfo ); // attachmentInfo ownership was transferred. |
|
458 } |
|
459 else |
|
460 { |
|
461 // if error, attachmentinfo ownership was not transferred |
|
462 CleanupStack::PopAndDestroy( attachmentInfo ); |
|
463 } |
|
464 // Error about unsuccessful attachment info modification is not returned to caller. |
|
465 // The attachment size info is unreliable anyway, actual file size should always be called |
|
466 |
|
467 return error; |
|
468 } |
|
469 |
|
470 // ================= OTHER EXPORTED FUNCTIONS ============== |
|
471 |
|
472 // End of File |