|
1 /* |
|
2 * Copyright (c) 2005-2009 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: File Transfer Controller implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <pathinfo.h> |
|
22 #include <stringresourcereader.h> |
|
23 #include <bautils.h> |
|
24 #include <driveinfo.h> |
|
25 #include <sconftp.rsg> |
|
26 #include <centralrepository.h> |
|
27 #include <sysutildomaincrkeys.h> |
|
28 |
|
29 #include "debug.h" |
|
30 #include "sconftp.h" |
|
31 #include "sconfshandler.h" |
|
32 #include "sconinboxhandler.h" |
|
33 #include "sconconsts.h" |
|
34 |
|
35 const TInt KPackageSize = 65536; |
|
36 |
|
37 // ============================= MEMBER FUNCTIONS =============================== |
|
38 |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CreateCSConFTPL() |
|
42 // Entry to CSConFTP |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 EXPORT_C CSConFTP* CreateCSConFTPL() |
|
46 { |
|
47 TRACE_FUNC; |
|
48 return CSConFTP::NewL(); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CSConFTP::NewL() |
|
53 // Two-phase constructor |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CSConFTP* CSConFTP::NewL() |
|
57 { |
|
58 TRACE_FUNC_ENTRY; |
|
59 CSConFTP* self = new (ELeave) CSConFTP(); |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 TRACE_FUNC_EXIT; |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSConFTP::~CSConFTP() |
|
69 // Destructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSConFTP::~CSConFTP() |
|
73 { |
|
74 TRACE_FUNC_ENTRY; |
|
75 delete iSConInboxHandler; |
|
76 iSConInboxHandler = NULL; |
|
77 delete iSConFsHandler; |
|
78 iSConFsHandler = NULL; |
|
79 delete iBuffer; |
|
80 iBuffer = NULL; |
|
81 |
|
82 iFs.Delete( iTempFileName ); |
|
83 iFs.Close(); |
|
84 TRACE_FUNC_EXIT; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CSConFTP::GetFolderObjectL( CObexBufObject*& aObjectList ) |
|
89 // Gets object that contains folder listing from inbox or file system |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt CSConFTP::GetFolderObjectL( CObexBufObject*& aObjectList ) |
|
93 { |
|
94 TRACE_FUNC_ENTRY; |
|
95 |
|
96 TInt ret( KErrNone ); |
|
97 TInt offset = 0; |
|
98 TChar driveLetter; |
|
99 TBuf8<KSConDriveNameLength> tmpBuf8; |
|
100 |
|
101 iBuffer->Reset(); |
|
102 |
|
103 //default folder list - lists all available drives, inbox |
|
104 if( iPathName.Length() == 0 ) |
|
105 { |
|
106 TInt devDriveCount = 0; |
|
107 TInt mmcDriveCount = 0; |
|
108 |
|
109 iBuffer->ResizeL( KSConXmlDocBegin().Length() ); |
|
110 iBuffer->Write( offset, KSConXmlDocBegin ); |
|
111 offset += KSConXmlDocBegin().Length(); |
|
112 |
|
113 //Write all drivers to folderlisting object |
|
114 TDriveList driveList; |
|
115 // Get all drives that are visible to the user. |
|
116 TInt driveCount; |
|
117 User::LeaveIfError( DriveInfo::GetUserVisibleDrives( iFs, driveList, driveCount ) ); |
|
118 |
|
119 for( TInt i = EDriveA; i < KMaxDrives; i++ ) |
|
120 { |
|
121 if( driveList[i] ) |
|
122 { |
|
123 TUint driveStatus; |
|
124 User::LeaveIfError( DriveInfo::GetDriveStatus( iFs, i, driveStatus ) ); |
|
125 LOGGER_WRITE_1( "DriveInfo for drive: %d", i); |
|
126 |
|
127 if( !(driveStatus & DriveInfo::EDrivePresent ) |
|
128 || driveStatus & DriveInfo::EDriveCorrupt |
|
129 || (driveStatus & DriveInfo::EDriveRemote) ) |
|
130 { |
|
131 LOGGER_WRITE_1( "skip drive %d", i); |
|
132 continue; |
|
133 } |
|
134 |
|
135 User::LeaveIfError( iFs.DriveToChar( i, driveLetter ) ); |
|
136 |
|
137 //Letter to uppercase form. |
|
138 driveLetter.UpperCase(); |
|
139 |
|
140 //Folder begin |
|
141 iBuffer->ExpandL( offset, |
|
142 KSConXmlFolderNameBegin().Length() ); |
|
143 iBuffer->Write( offset, KSConXmlFolderNameBegin ); |
|
144 offset += KSConXmlFolderNameBegin().Length(); |
|
145 |
|
146 iBuffer->ExpandL( offset, KSConDriveCName().Length() ); |
|
147 |
|
148 tmpBuf8.Delete( 0, tmpBuf8.Length() ); |
|
149 tmpBuf8.Append( driveLetter ); |
|
150 tmpBuf8.Append( KDriveDelimiter ); |
|
151 |
|
152 iBuffer->Write( offset, tmpBuf8 ); |
|
153 offset += KSConDriveNameLength; |
|
154 |
|
155 //permission |
|
156 iBuffer->ExpandL( offset, |
|
157 KSConXmlUserAttributes().Length() ); |
|
158 iBuffer->Write( offset, KSConXmlUserAttributes ); |
|
159 offset += KSConXmlUserAttributes().Length(); |
|
160 if( driveStatus & DriveInfo::EDriveInternal && devDriveCount==0 ) |
|
161 { |
|
162 //permission always R for first internal drive |
|
163 iBuffer->ExpandL( offset, |
|
164 KSConXmlUserEntryReadOnly().Length() ); |
|
165 iBuffer->Write( offset, KSConXmlUserEntryReadOnly ); |
|
166 offset += KSConXmlUserEntryReadOnly().Length(); |
|
167 } |
|
168 else |
|
169 { |
|
170 //permission always RW |
|
171 iBuffer->ExpandL( offset, |
|
172 KSConXmlUserEntryDrive().Length() ); |
|
173 iBuffer->Write( offset, KSConXmlUserEntryDrive ); |
|
174 offset += KSConXmlUserEntryDrive().Length(); |
|
175 } |
|
176 |
|
177 //memory type |
|
178 iBuffer->ExpandL( offset, |
|
179 KSConXmlMemoryType().Length() ); |
|
180 iBuffer->Write( offset, KSConXmlMemoryType ); |
|
181 offset += KSConXmlMemoryType().Length(); |
|
182 if( driveStatus & DriveInfo::EDriveInternal ) |
|
183 { |
|
184 LOGGER_WRITE( "DriveInfo::EDriveInternal" ); |
|
185 // DEV type |
|
186 devDriveCount++; |
|
187 if( devDriveCount > 1 ) |
|
188 { |
|
189 // DEV2 |
|
190 TBuf8<KSConMemTypeMaxLength> memType; |
|
191 memType.Copy( KSConMemoryTypeDev ); |
|
192 memType.AppendNum(devDriveCount); |
|
193 iBuffer->ExpandL( offset, memType.Length() ); |
|
194 iBuffer->Write( offset, memType ); |
|
195 offset += memType.Length(); |
|
196 } |
|
197 else |
|
198 { |
|
199 // DEV |
|
200 iBuffer->ExpandL( offset, |
|
201 KSConMemoryTypeDev().Length() ); |
|
202 iBuffer->Write( offset, KSConMemoryTypeDev ); |
|
203 offset += KSConMemoryTypeDev().Length(); |
|
204 } |
|
205 } |
|
206 if( driveStatus & DriveInfo::EDriveRemovable ) |
|
207 { |
|
208 LOGGER_WRITE( "DriveInfo::EDriveRemovable" ); |
|
209 // MMC type |
|
210 mmcDriveCount++; |
|
211 if( mmcDriveCount > 1 ) |
|
212 { |
|
213 // MMC2 |
|
214 TBuf8<KSConMemTypeMaxLength> memType; |
|
215 memType.Copy( KSConMemoryTypeMmc ); |
|
216 memType.AppendNum(mmcDriveCount); |
|
217 iBuffer->ExpandL( offset, memType.Length() ); |
|
218 iBuffer->Write( offset, memType ); |
|
219 offset += memType.Length(); |
|
220 } |
|
221 else |
|
222 { |
|
223 // MMC |
|
224 iBuffer->ExpandL( offset, |
|
225 KSConMemoryTypeMmc().Length() ); |
|
226 iBuffer->Write( offset, KSConMemoryTypeMmc ); |
|
227 offset += KSConMemoryTypeMmc().Length(); |
|
228 } |
|
229 } |
|
230 |
|
231 //memory label |
|
232 iBuffer->ExpandL( offset, |
|
233 KSConXmlMemoryLabel().Length() ); |
|
234 iBuffer->Write( offset, KSConXmlMemoryLabel ); |
|
235 offset += KSConXmlMemoryLabel().Length(); |
|
236 |
|
237 TInt err( KErrNotFound ); |
|
238 TBuf8<KMaxFileName> volumeName; |
|
239 if( driveStatus & DriveInfo::EDriveRemovable || devDriveCount == 1 ) |
|
240 { |
|
241 // get Volume name for C-drive(Phone) and E-drive(MMC) |
|
242 err = GetVolumeNameL( i, volumeName ); |
|
243 } |
|
244 else |
|
245 { |
|
246 // Get localized name for DEV2 (Mass memory) |
|
247 //Read memory string and convert it |
|
248 TFileName file( KSConResourceName ); |
|
249 |
|
250 BaflUtils::NearestLanguageFile( iFs, file ); |
|
251 |
|
252 CStringResourceReader* reader = CStringResourceReader::NewL( file ); |
|
253 |
|
254 CnvUtfConverter::ConvertFromUnicodeToUtf8( volumeName, |
|
255 reader->ReadResourceString( R_SECON_VALUE_MASS_STORAGE ) ); |
|
256 |
|
257 delete reader; |
|
258 err = KErrNone; |
|
259 } |
|
260 |
|
261 if ( err == KErrNone ) |
|
262 { |
|
263 iBuffer->ExpandL( offset, |
|
264 volumeName.Length() ); |
|
265 iBuffer->Write( offset, volumeName ); |
|
266 offset += volumeName.Length(); |
|
267 } |
|
268 |
|
269 //Write the end of filelist to folderlisting object |
|
270 iBuffer->ExpandL( offset, KSConXmlFileEnd().Length() ); |
|
271 iBuffer->Write( offset, KSConXmlFileEnd ); |
|
272 offset += KSConXmlFileEnd().Length(); |
|
273 } |
|
274 } |
|
275 //Write the end of folderlist to folderlisting object |
|
276 iBuffer->ExpandL( offset, KSConXmlFolderListEnd().Length() ); |
|
277 iBuffer->Write( offset, KSConXmlFolderListEnd ); |
|
278 iBuffer->Compress(); |
|
279 } |
|
280 else |
|
281 { |
|
282 if( IsCurrentVolumeOK() ) |
|
283 { |
|
284 ret = iSConFsHandler->ParseFolderListL( iBuffer, iPathName, iCurrentDriveTypeNumber ); |
|
285 } |
|
286 else |
|
287 { |
|
288 ret = KErrNotFound; |
|
289 } |
|
290 } |
|
291 |
|
292 //Put data to aObjectList |
|
293 delete aObjectList; |
|
294 aObjectList = NULL; |
|
295 |
|
296 aObjectList = CObexBufObject::NewL( iBuffer ); |
|
297 aObjectList->SetTypeL( KSConFolderListType ); |
|
298 aObjectList->SetLengthL( iBuffer->Size() ); |
|
299 |
|
300 LOGGER_WRITE_1( "CSConFTP::GetFolderObjectL( CObexBufObject*& aObjectList ) : returned %d", ret ); |
|
301 return ret; |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CSConFTP::GetFileObjectL( CObexFileObject*& aFileObject ) |
|
306 // Gets object that contains a file from file system |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 TInt CSConFTP::GetFileObjectL( CObexFileObject*& aFileObject ) |
|
310 { |
|
311 TRACE_FUNC_ENTRY; |
|
312 |
|
313 TInt ret( KErrNone ); |
|
314 |
|
315 if( aFileObject->Name().Length() == 0 ) |
|
316 { |
|
317 return KErrBadName; |
|
318 } |
|
319 |
|
320 // check is current drive ok |
|
321 if( iPathName.Length() > 0 ) |
|
322 { |
|
323 TPath path( KSConAllowedPath ); |
|
324 path.Append( KPathDelimiter ); |
|
325 if( iPathName.CompareF( path ) != 0 ) |
|
326 { |
|
327 // was normal path (not KSConAllowedPath) |
|
328 if( !IsCurrentVolumeOK() ) |
|
329 { |
|
330 return KErrNotFound; |
|
331 } |
|
332 } |
|
333 } |
|
334 |
|
335 HBufC* nameBuf = HBufC::NewLC( KMaxFileName ); |
|
336 TPtr namePtr = nameBuf->Des(); |
|
337 namePtr.Append( aFileObject->Name() ); |
|
338 |
|
339 if( namePtr.LocateReverse( KPathDelimiter ) == namePtr.Length()-1 ) |
|
340 { |
|
341 namePtr.Delete( namePtr.Length()-1, 1 ); |
|
342 } |
|
343 |
|
344 ret = iSConFsHandler->GetFileObjectL( aFileObject, iPathName, namePtr ); |
|
345 |
|
346 CleanupStack::PopAndDestroy( nameBuf ); |
|
347 |
|
348 LOGGER_WRITE_1( "CSConFTP::GetFileObjectL() : returned %d", ret ); |
|
349 return ret; |
|
350 } |
|
351 |
|
352 // ----------------------------------------------------------------------------- |
|
353 // CSConFTP::PutFileObjectInitL( CObexBufObject*& aObject, |
|
354 // CBufFlat*& aBuffer ) |
|
355 // Initializes the receiving from the client. |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 TInt CSConFTP::PutFileObjectInitL( CObexBufObject*& aObject, |
|
359 CBufFlat*& aBuffer ) |
|
360 { |
|
361 TRACE_FUNC_ENTRY; |
|
362 TInt ret( KErrNone ); |
|
363 |
|
364 RFile file; |
|
365 |
|
366 TBool lowMemory = IsCurrentDiskSpaceBelowCritical(); |
|
367 |
|
368 //if Inbox then save temp file to default drive |
|
369 if( iPathName.Length() == 0 ) |
|
370 { |
|
371 //When proprietary profile (PC Suite), doesn't allow to use Inbox |
|
372 if( iProfile == EProprietary ) |
|
373 { |
|
374 LOGGER_WRITE( "CSConFTP::PutFileObjectInitL() : iProfile EProprietary" ); |
|
375 ret = file.Temp( iFs, PathInfo::PhoneMemoryRootPath(), iTempFileName, |
|
376 EFileWrite | EFileShareExclusive ); |
|
377 file.Close(); |
|
378 |
|
379 if( ret == KErrNone ) |
|
380 { |
|
381 delete aObject; |
|
382 aObject = CObexBufObject::NewL( NULL ); |
|
383 |
|
384 if( aBuffer ) |
|
385 { |
|
386 aBuffer->Reset(); |
|
387 delete aBuffer; |
|
388 } |
|
389 |
|
390 aBuffer = CBufFlat::NewL( KSConBufferSize ); |
|
391 aBuffer->ResizeL( KSConBufferSize ); |
|
392 |
|
393 TObexFilenameBackedBuffer bufferdetails( *aBuffer, iTempFileName, |
|
394 CObexBufObject::EDoubleBuffering ); |
|
395 aObject->SetDataBufL( bufferdetails ); |
|
396 } |
|
397 } |
|
398 else |
|
399 { |
|
400 LOGGER_WRITE( "CSConFTP::PutFileObjectInitL() : not EProprietary" ); |
|
401 if( lowMemory ) |
|
402 { |
|
403 // do not even try to save |
|
404 LOGGER_WRITE( "CSConFTP::PutFileObjectInitL() : disk full" ); |
|
405 ret = KErrNoMemory; |
|
406 } |
|
407 else |
|
408 { |
|
409 ret = iSConInboxHandler->CreateInboxAttachmentL( aObject, aBuffer ); |
|
410 } |
|
411 } |
|
412 |
|
413 return ret; |
|
414 } |
|
415 else |
|
416 { |
|
417 LOGGER_WRITE_1("iPathName: %S", &iPathName); |
|
418 // check is current drive ok |
|
419 if( !IsCurrentVolumeOK() ) |
|
420 { |
|
421 LOGGER_WRITE( "CSConFTP::PutFileObjectInitL() : drive not visible" ); |
|
422 ret = KErrNotFound; |
|
423 } |
|
424 else |
|
425 { |
|
426 ret = file.Temp( iFs, iPathName, iTempFileName, EFileWrite | |
|
427 EFileShareExclusive ); |
|
428 } |
|
429 } |
|
430 |
|
431 file.Close(); |
|
432 |
|
433 if( ret == KErrNone ) |
|
434 { |
|
435 delete aObject; |
|
436 aObject = CObexBufObject::NewL( NULL ); |
|
437 |
|
438 if( aBuffer ) |
|
439 { |
|
440 aBuffer->Reset(); |
|
441 delete aBuffer; |
|
442 } |
|
443 |
|
444 aBuffer = CBufFlat::NewL( KSConBufferSize ); |
|
445 aBuffer->ResizeL( KSConBufferSize ); |
|
446 |
|
447 TObexFilenameBackedBuffer bufferdetails( *aBuffer, iTempFileName, |
|
448 CObexBufObject::EDoubleBuffering ); |
|
449 aObject->SetDataBufL( bufferdetails ); |
|
450 |
|
451 if( lowMemory ) |
|
452 { |
|
453 // return error. it's up to pccon/ftp plugin howto handle it.. |
|
454 LOGGER_WRITE( "CSConFTP::PutFileObjectInitL() : low memory" ); |
|
455 ret = KErrNoMemory; |
|
456 } |
|
457 } |
|
458 |
|
459 LOGGER_WRITE_1( "CSConFTP::PutFileObjectInitL( CObexBufObject*& aObject, CBufFlat*& aBuffer ) : returned %d", ret ); |
|
460 return ret; |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CSConFTP::PutFileObjectFinalizeL( CObexBufObject*& aObject ) |
|
465 // Stores the relayed file object to inbox or file system. |
|
466 // ----------------------------------------------------------------------------- |
|
467 // |
|
468 TInt CSConFTP::PutFileObjectFinalizeL( CObexBufObject*& aObject ) |
|
469 { |
|
470 TRACE_FUNC_ENTRY; |
|
471 TInt ret( KErrNone ); |
|
472 |
|
473 // if iPathName is not defined trying to save to inbox, no need to call IsCurrentVolumeOK() |
|
474 if( iPathName.Length() > 0 && !IsCurrentVolumeOK() ) |
|
475 { |
|
476 // Memory card removed |
|
477 LOGGER_WRITE( "CSConFTP::PutFileObjectFinalizeL() : disk err, return KErrNotFound" ); |
|
478 return KErrNotFound; |
|
479 } |
|
480 else if ( iPathName.Length() + aObject->Name().Length() > KMaxFileName ) |
|
481 { |
|
482 LOGGER_WRITE( "CSConFTP::PutFileObjectFinalizeL() : Too long filename, return KErrBadName"); |
|
483 return KErrBadName; |
|
484 } |
|
485 |
|
486 TBool lowMemory = IsCurrentDiskSpaceBelowCritical(); |
|
487 if ( lowMemory ) |
|
488 { |
|
489 LOGGER_WRITE( "CSConFTP::PutFileObjectFinalizeL() : Low memory, return KErrNoMemory"); |
|
490 return KErrNoMemory; |
|
491 } |
|
492 |
|
493 HBufC* fullPathBuf = HBufC::NewLC( KMaxFileName ); |
|
494 TPtr fullPathPtr = fullPathBuf->Des(); |
|
495 fullPathPtr.Copy( iPathName ); |
|
496 fullPathPtr.Append( aObject->Name() ); |
|
497 |
|
498 // Save to inbox if path is not set. |
|
499 if( iPathName.Length() == 0 ) |
|
500 { |
|
501 LOGGER_WRITE( "CSConFTP::PutFileObjectFinalizeL before SaveObjectToInbox" ); |
|
502 ret = iSConInboxHandler->SaveObjToInboxL( aObject ); |
|
503 LOGGER_WRITE_1( "CSConFTP::PutFileObjectFinalize SaveObjectToInbox returned %d", ret ); |
|
504 } |
|
505 else if( iPathName.CompareF( K_C_ROOT ) == 0 ) |
|
506 { |
|
507 // Saving to root of C:\ is not allowed |
|
508 ret = KErrAccessDenied; |
|
509 } |
|
510 //Save to file system |
|
511 else |
|
512 { |
|
513 TTime time = aObject->Time(); |
|
514 |
|
515 // UTC offset |
|
516 time -= User::UTCOffset(); |
|
517 |
|
518 delete aObject; |
|
519 aObject = NULL; |
|
520 |
|
521 ret = iSConFsHandler->SaveFileObjectL( fullPathPtr, time, |
|
522 iTempFileName ); |
|
523 } |
|
524 |
|
525 CleanupStack::PopAndDestroy( fullPathBuf ); |
|
526 |
|
527 LOGGER_WRITE_1( "CSConFTP::PutFileObjectFinalizeL( CObexBufObject*& aObject ) : returned %d", ret ); |
|
528 |
|
529 return ret; |
|
530 } |
|
531 |
|
532 // ----------------------------------------------------------------------------- |
|
533 // CSConFTP::SetPathL( const TPtrC aPath, const TUint8 aFlags ) |
|
534 // Changes the current path. The path can point to inbox or file system |
|
535 // ----------------------------------------------------------------------------- |
|
536 // |
|
537 TInt CSConFTP::SetPathL( const TPtrC aPath, const TUint8 aFlags ) |
|
538 { |
|
539 TRACE_FUNC_ENTRY; |
|
540 LOGGER_WRITE_1( "aPath: %S", &aPath ); |
|
541 TInt ret( KErrNone ); |
|
542 |
|
543 if( ( aPath.Length() > 0 && aFlags != KSConSetPathRoot ) |
|
544 || ( iPathName.Length() == KDriveLength && aFlags == KSConSetPathBack) ) |
|
545 { |
|
546 // check is current drive ok |
|
547 if( !IsCurrentVolumeOK() ) |
|
548 { |
|
549 LOGGER_WRITE( "CSConFTP::SetPathL() : drive not found" ); |
|
550 return KErrNotFound; |
|
551 } |
|
552 } |
|
553 |
|
554 ret = KErrNotFound; |
|
555 |
|
556 //path forward, deny access to forbidden directories and drives |
|
557 if( aPath.Length() > 0 |
|
558 && ( iPathName.Length() + aPath.Length() < KMaxFileName ) |
|
559 && ( aFlags == KSConSetPathForward || aFlags == KSConSetPathDontCreate ) ) |
|
560 { |
|
561 ret = SetPathForwardL( aPath, aFlags ); |
|
562 } |
|
563 //path backward |
|
564 else if( aFlags == KSConSetPathBack ) |
|
565 { |
|
566 ret = SetPathBackwardL( aPath ); |
|
567 } |
|
568 //path root |
|
569 else if( aPath.Length() == 0 && aFlags == KSConSetPathRoot ) |
|
570 { |
|
571 LOGGER_WRITE( "CSConFTP::SetPathL() : KSConSetPathRoot" ); |
|
572 if( iPathName.Length() > 0 ) |
|
573 { |
|
574 iPathName.Delete( 0, iPathName.Length() ); |
|
575 } |
|
576 iCurrentDrive = KErrNotFound; |
|
577 ret = KErrNone; |
|
578 } |
|
579 |
|
580 if( ret == KErrNone ) |
|
581 { |
|
582 // drive may have changed, update info |
|
583 UpdateDriveTypeInfoL(); |
|
584 } |
|
585 |
|
586 LOGGER_WRITE_1( "CSConFTP::CSConFTP::SetPathL( const TPtrC aPath, const TUint8 aFlags ) : returned %d", ret ); |
|
587 return ret; |
|
588 } |
|
589 |
|
590 // ----------------------------------------------------------------------------- |
|
591 // CSConFTP::SetPathForwardL( const TPtrC aPath, const TUint8 aFlags ) |
|
592 // Set path forward |
|
593 // ----------------------------------------------------------------------------- |
|
594 // |
|
595 TInt CSConFTP::SetPathForwardL( const TPtrC aPath, const TUint8 aFlags ) |
|
596 { |
|
597 TRACE_FUNC_ENTRY; |
|
598 TInt ret(KErrNone); |
|
599 HBufC* fullPath = HBufC::NewLC( KMaxFileName ); |
|
600 TPtr fullPathPtr = fullPath->Des(); |
|
601 |
|
602 if( iPathName.Length() == 0 ) |
|
603 { |
|
604 fullPathPtr.Copy( aPath ); |
|
605 } |
|
606 else |
|
607 { |
|
608 fullPathPtr.Copy( iPathName ); |
|
609 fullPathPtr.Append( aPath ); |
|
610 } |
|
611 LOGGER_WRITE_1( "fullPathPtr: %S", &fullPathPtr ); |
|
612 // now fullpath is new path |
|
613 // check validity |
|
614 if( fullPathPtr.Length() < 2 || fullPathPtr[1] != KDriveDelimiter ) |
|
615 { |
|
616 LOGGER_WRITE( "CSConFTP::SetPathForwardL() : not valid name" ); |
|
617 CleanupStack::PopAndDestroy( fullPath ); |
|
618 return KErrNotFound; |
|
619 } |
|
620 |
|
621 if( fullPathPtr.CompareF( KSConAllowedPath ) == 0 ) |
|
622 { |
|
623 // Always access to PC Suite configuration file on ROM |
|
624 LOGGER_WRITE( "CSConFTP::SetPathForwardL() : KSConAllowedPath" ); |
|
625 iPathName.Copy( fullPathPtr ); |
|
626 if( iPathName[iPathName.Length()-1] != KPathDelimiter ) |
|
627 { |
|
628 iPathName.Append( KPathDelimiter ); |
|
629 } |
|
630 |
|
631 CleanupStack::PopAndDestroy( fullPath ); |
|
632 return KErrNone; |
|
633 } |
|
634 |
|
635 // check drive |
|
636 TInt driveNumber; |
|
637 TInt err = iFs.CharToDrive( fullPathPtr[0], driveNumber ); |
|
638 if( err != KErrNone || !IsDriveVisible( driveNumber ) ) |
|
639 { |
|
640 LOGGER_WRITE( "CSConFTP::SetPathForwardL() : drive err" ); |
|
641 CleanupStack::PopAndDestroy( fullPath ); |
|
642 return KErrNotFound; |
|
643 } |
|
644 |
|
645 // check folder and create it if needed |
|
646 if( fullPathPtr.Length() > 2 ) |
|
647 { |
|
648 TBool isFolder = EFalse; |
|
649 err = BaflUtils::IsFolder( iFs, fullPathPtr, isFolder ); |
|
650 if( err != KErrNone ) |
|
651 { |
|
652 isFolder = EFalse; |
|
653 } |
|
654 LOGGER_WRITE_1( "CSConFTP::SetPathForwardL() IsFolder: %d", (TInt)isFolder ); |
|
655 |
|
656 if( !isFolder ) |
|
657 { |
|
658 //if "Don't create" is 1 |
|
659 if( aFlags & 2 ) |
|
660 { |
|
661 ret = KErrNotFound; |
|
662 } |
|
663 else |
|
664 { |
|
665 CreateFolderL( fullPathPtr ); |
|
666 ret = KErrNone; |
|
667 } |
|
668 } |
|
669 else |
|
670 { |
|
671 ret = KErrNone; |
|
672 } |
|
673 } |
|
674 else |
|
675 { |
|
676 ret = KErrNone; |
|
677 } |
|
678 |
|
679 if( ret == KErrNone ) |
|
680 { |
|
681 iPathName.Copy( fullPathPtr ); |
|
682 |
|
683 if( iPathName[iPathName.Length()-1] != KPathDelimiter ) |
|
684 { |
|
685 iPathName.Append( KPathDelimiter ); |
|
686 } |
|
687 } |
|
688 |
|
689 CleanupStack::PopAndDestroy( fullPath ); |
|
690 LOGGER_WRITE_1( "CSConFTP::SetPathForwardL() : end, ret: %d", ret ); |
|
691 return ret; |
|
692 |
|
693 } |
|
694 |
|
695 // ----------------------------------------------------------------------------- |
|
696 // CSConFTP::SetPathBackwardL( const TPtrC aPath ) |
|
697 // Set path backward |
|
698 // ----------------------------------------------------------------------------- |
|
699 // |
|
700 TInt CSConFTP::SetPathBackwardL( const TPtrC aPath ) |
|
701 { |
|
702 TRACE_FUNC_ENTRY; |
|
703 TInt ret(KErrNotFound); |
|
704 if( iPathName.Length() == 0 ) |
|
705 { |
|
706 // already in root, exit |
|
707 LOGGER_WRITE( "CSConFTP::SetPathBackwardL() : already in root" ); |
|
708 LOGGER_WRITE_1( "CSConFTP::SetPathBackwardL() : end, ret: %d", ret ); |
|
709 return ret; |
|
710 } |
|
711 TInt pos; |
|
712 TBool isFolder(EFalse); |
|
713 HBufC* fullPath = HBufC::NewLC( KMaxFileName ); |
|
714 TPtr fullPathPtr = fullPath->Des(); |
|
715 |
|
716 //no directory/folder name |
|
717 if( aPath.Length() == 0 ) |
|
718 { |
|
719 LOGGER_WRITE( "CSConFTP::SetPathBackwardL() : no new path, goto parent" ); |
|
720 iPathName.Delete( iPathName.Length()-1, 1 ); |
|
721 pos = iPathName.LocateReverse( KPathDelimiter ); |
|
722 iPathName.Delete( pos+1, iPathName.Length()-pos ); |
|
723 ret = KErrNone; |
|
724 } |
|
725 //if folder name |
|
726 else if( aPath.Locate( KDriveDelimiter ) != 1 && iPathName.Length() > KDriveLength ) |
|
727 { |
|
728 LOGGER_WRITE( "CSConFTP::SetPathBackwardL() : goto parent and new path" ); |
|
729 fullPathPtr.Copy( iPathName ); |
|
730 fullPathPtr.Delete( fullPathPtr.Length()-1, 1 ); |
|
731 pos = fullPathPtr.LocateReverse( KPathDelimiter ); |
|
732 fullPathPtr.Delete( pos+1, fullPathPtr.Length()-pos ); |
|
733 fullPathPtr.Append( aPath ); |
|
734 |
|
735 if( fullPathPtr.CompareF( KSConAllowedPath ) == 0 ) |
|
736 { |
|
737 // Always access to PC Suite configuration file on ROM |
|
738 isFolder = ETrue; |
|
739 } |
|
740 else |
|
741 { |
|
742 TInt driveNumber; |
|
743 TInt err = iFs.CharToDrive(fullPathPtr[0], driveNumber); |
|
744 if( err != KErrNone ) |
|
745 { |
|
746 LOGGER_WRITE( "CSConFTP::SetPathForwardL() : drive err" ); |
|
747 isFolder = EFalse; |
|
748 } |
|
749 else if( !IsDriveVisible(driveNumber) ) |
|
750 { |
|
751 isFolder = EFalse; |
|
752 } |
|
753 else |
|
754 { |
|
755 // drive ok, check folder. |
|
756 err = BaflUtils::IsFolder( iFs, fullPathPtr, isFolder ); |
|
757 if( err != KErrNone ) |
|
758 { |
|
759 isFolder = EFalse; |
|
760 } |
|
761 } |
|
762 } |
|
763 |
|
764 if( isFolder ) |
|
765 { |
|
766 iPathName.Copy( fullPathPtr ); |
|
767 |
|
768 if( aPath.LocateReverse( KPathDelimiter ) != aPath.Length()-1 ) |
|
769 { |
|
770 iPathName.Append( KPathDelimiter ); |
|
771 } |
|
772 |
|
773 ret = KErrNone; |
|
774 } |
|
775 else |
|
776 { |
|
777 ret = KErrNotFound; |
|
778 } |
|
779 |
|
780 } |
|
781 //drive |
|
782 else if( aPath.Locate( KDriveDelimiter ) == 1 ) |
|
783 { |
|
784 fullPathPtr.Copy( aPath ); |
|
785 if( fullPathPtr.LocateReverse( KPathDelimiter ) |
|
786 != fullPathPtr.Length()-1 ) |
|
787 { |
|
788 fullPathPtr.Append( KPathDelimiter ); |
|
789 } |
|
790 |
|
791 TFileName tempPath( KSConAllowedPath ); |
|
792 tempPath.Append(KPathDelimiter); |
|
793 if( fullPathPtr.CompareF( tempPath ) == 0 ) |
|
794 { |
|
795 // Always access to PC Suite configuration file on ROM |
|
796 isFolder = ETrue; |
|
797 } |
|
798 else |
|
799 { |
|
800 TInt driveNumber; |
|
801 TInt err = iFs.CharToDrive(fullPathPtr[0], driveNumber); |
|
802 if( err != KErrNone ) |
|
803 { |
|
804 LOGGER_WRITE( "CSConFTP::SetPathForwardL() : drive err" ); |
|
805 isFolder = EFalse; |
|
806 } |
|
807 else if( !IsDriveVisible(driveNumber) ) |
|
808 { |
|
809 isFolder = EFalse; |
|
810 } |
|
811 else |
|
812 { |
|
813 // drive ok, check folder. |
|
814 err = BaflUtils::IsFolder( iFs, fullPathPtr, isFolder ); |
|
815 if( err != KErrNone ) |
|
816 { |
|
817 isFolder = EFalse; |
|
818 } |
|
819 } |
|
820 } |
|
821 |
|
822 if( isFolder ) |
|
823 { |
|
824 iPathName.Copy( fullPathPtr ); |
|
825 |
|
826 if( aPath.LocateReverse( KPathDelimiter ) != aPath.Length()-1 ) |
|
827 { |
|
828 iPathName.Append( KPathDelimiter ); |
|
829 } |
|
830 |
|
831 ret = KErrNone; |
|
832 } |
|
833 else |
|
834 { |
|
835 ret = KErrNotFound; |
|
836 } |
|
837 } |
|
838 CleanupStack::PopAndDestroy( fullPath ); |
|
839 LOGGER_WRITE_1( "CSConFTP::SetPathBackwardL() : end, ret: %d", ret ); |
|
840 return ret; |
|
841 } |
|
842 |
|
843 // ----------------------------------------------------------------------------- |
|
844 // CSConFTP::CreateFolderL( const TPtrC aFolderName ) |
|
845 // Creates a new folder to file system |
|
846 // ----------------------------------------------------------------------------- |
|
847 // |
|
848 TInt CSConFTP::CreateFolderL( const TPtrC aFolderName ) |
|
849 { |
|
850 TRACE_FUNC_ENTRY; |
|
851 LOGGER_WRITE_1( "aFolderName: %S", &aFolderName ); |
|
852 TInt ret( KErrNone ); |
|
853 if( aFolderName.Length() == 0 ) |
|
854 { |
|
855 return KErrArgument; |
|
856 } |
|
857 |
|
858 HBufC* pathBuf = HBufC::NewLC( KMaxFileName ); |
|
859 TPtr pathBufPtr = pathBuf->Des(); |
|
860 //absolute folder path |
|
861 if( aFolderName.Length() > 1 && aFolderName[1] == KDriveDelimiter ) |
|
862 { |
|
863 if ( iPathName.Length()>0 ) |
|
864 { |
|
865 LOGGER_WRITE( "CSConFTP::CreateFolderL() : KErrBadName" ); |
|
866 CleanupStack::PopAndDestroy( pathBuf ); |
|
867 return KErrBadName; |
|
868 } |
|
869 pathBufPtr.Copy( aFolderName ); |
|
870 } |
|
871 else |
|
872 { |
|
873 pathBufPtr.Copy( iPathName ); |
|
874 pathBufPtr.Append( aFolderName ); |
|
875 } |
|
876 |
|
877 if( !iFs.IsValidName( pathBufPtr ) ) |
|
878 { |
|
879 ret = KErrBadName; |
|
880 } |
|
881 else |
|
882 { |
|
883 // check drive |
|
884 TInt driveNumber; |
|
885 ret = iFs.CharToDrive(pathBufPtr[0], driveNumber); |
|
886 if( ret != KErrNone || !IsDriveVisible(driveNumber) ) |
|
887 { |
|
888 LOGGER_WRITE( "CSConFTP::CreateFolderL() : drive err" ); |
|
889 ret = KErrNotFound; |
|
890 } |
|
891 } |
|
892 |
|
893 if ( ret == KErrNone ) |
|
894 { |
|
895 if( pathBufPtr.LocateReverse( KPathDelimiter ) != pathBufPtr.Length()-1 ) |
|
896 { |
|
897 pathBufPtr.Append( KPathDelimiter ); |
|
898 } |
|
899 ret = iSConFsHandler->CreateFolderL( pathBufPtr ); |
|
900 } |
|
901 |
|
902 if( ret == KErrNone || ret == KErrAlreadyExists ) |
|
903 { |
|
904 ret = SetPathL( aFolderName, KSConSetPathForward ); |
|
905 } |
|
906 |
|
907 CleanupStack::PopAndDestroy( pathBuf ); |
|
908 |
|
909 LOGGER_WRITE_1( "CSConFTP::CreateFolderL( const TPtrC aFolderName ) : returned %d", ret ); |
|
910 |
|
911 return ret; |
|
912 } |
|
913 |
|
914 // ----------------------------------------------------------------------------- |
|
915 // CSConFTP::DeleteObjectL( const TPtrC aObjectName ) |
|
916 // Deletes file/folder from inbox or file system |
|
917 // ----------------------------------------------------------------------------- |
|
918 // |
|
919 TInt CSConFTP::DeleteObjectL( const TPtrC aObjectName ) |
|
920 { |
|
921 TRACE_FUNC_ENTRY; |
|
922 LOGGER_WRITE_1( "aObjectName: %S", &aObjectName ); |
|
923 TInt ret( KErrNone ); |
|
924 TFileName tmpTarget; |
|
925 HBufC* targetBuf = HBufC::NewLC( KMaxFileName ); |
|
926 TPtr target = targetBuf->Des(); |
|
927 |
|
928 //absolute folder path |
|
929 if( aObjectName.Length() > 1 && aObjectName[1] == KDriveDelimiter ) |
|
930 { |
|
931 if ( iPathName.Length()>0 ) |
|
932 { |
|
933 LOGGER_WRITE( "CSConFTP::DeleteObjectL() : KErrBadName" ); |
|
934 CleanupStack::PopAndDestroy( targetBuf ); |
|
935 return KErrBadName; |
|
936 } |
|
937 target.Copy( aObjectName ); |
|
938 } |
|
939 else |
|
940 { |
|
941 target.Copy( iPathName ); |
|
942 target.Append( aObjectName ); |
|
943 } |
|
944 |
|
945 if( !iFs.IsValidName( target ) ) |
|
946 { |
|
947 ret = KErrBadName; |
|
948 } |
|
949 else |
|
950 { |
|
951 TInt driveNumber; |
|
952 ret = iFs.CharToDrive(target[0], driveNumber); |
|
953 if( ret != KErrNone || !IsDriveVisible(driveNumber) ) |
|
954 { |
|
955 LOGGER_WRITE( "CSConFTP::DeleteObjectL() : drive err" ); |
|
956 ret = KErrNotFound; |
|
957 } |
|
958 } |
|
959 |
|
960 |
|
961 if ( ret == KErrNone ) |
|
962 { |
|
963 ret = iSConFsHandler->DeleteObjectL( target ); |
|
964 } |
|
965 |
|
966 CleanupStack::PopAndDestroy( targetBuf ); |
|
967 |
|
968 LOGGER_WRITE_1( "CSConFTP::DeleteObjectL( const TPtrC aObjectName ) : returned %d", ret ); |
|
969 return ret; |
|
970 } |
|
971 |
|
972 // ----------------------------------------------------------------------------- |
|
973 // CSConFTP::GetPath( TDes& aPath ) |
|
974 // Gets the current path |
|
975 // ----------------------------------------------------------------------------- |
|
976 // |
|
977 TInt CSConFTP::GetPath( TDes& aPath ) |
|
978 { |
|
979 TRACE_FUNC; |
|
980 aPath.Copy( iPathName ); |
|
981 return KErrNone; |
|
982 } |
|
983 |
|
984 // ----------------------------------------------------------------------------- |
|
985 // CSConFTP::AbortFileTransfer( CObexBufObject*& aObject ) |
|
986 // Abort file transfer |
|
987 // ----------------------------------------------------------------------------- |
|
988 // |
|
989 TInt CSConFTP::AbortFileTransfer( CObexBufObject*& aObject ) |
|
990 { |
|
991 TRACE_FUNC_ENTRY; |
|
992 TInt err( KErrNone ); |
|
993 |
|
994 if( iPathName.Length() == 0 ) |
|
995 { |
|
996 iSConInboxHandler->AbortInboxOperation( aObject ); |
|
997 } |
|
998 |
|
999 //aObject has to be deleted, otherwise the temp file is locked |
|
1000 delete aObject; |
|
1001 aObject = NULL; |
|
1002 |
|
1003 err = iFs.Delete( iTempFileName ); |
|
1004 |
|
1005 LOGGER_WRITE_1( "CSConFTP::AbortFileTransfer( CObexBufObject*& aObject ) : iFs.Delete() err: %d", err ); |
|
1006 return err; |
|
1007 } |
|
1008 |
|
1009 // ----------------------------------------------------------------------------- |
|
1010 // CSConFTP::SetProfile( TInt aProfile ) |
|
1011 // Set used transfer profile |
|
1012 // ----------------------------------------------------------------------------- |
|
1013 // |
|
1014 void CSConFTP::SetProfile( TSConProfile aProfile ) |
|
1015 { |
|
1016 TRACE_FUNC; |
|
1017 iProfile = aProfile; |
|
1018 } |
|
1019 |
|
1020 // ----------------------------------------------------------------------------- |
|
1021 // CSConFTP::SetBackupStarted( TBool aValue ) |
|
1022 // Set backup status |
|
1023 // ----------------------------------------------------------------------------- |
|
1024 // |
|
1025 void CSConFTP::SetBackupStarted( TBool aValue ) |
|
1026 { |
|
1027 TRACE_FUNC; |
|
1028 iBackupStarted = aValue; |
|
1029 } |
|
1030 |
|
1031 // ----------------------------------------------------------------------------- |
|
1032 // CSConFTP::SetUsedMedia( TSConUsedMedia aMedia ) |
|
1033 // Set the used media information |
|
1034 // ----------------------------------------------------------------------------- |
|
1035 // |
|
1036 void CSConFTP::SetUsedMedia( TSConUsedMedia aMedia ) |
|
1037 { |
|
1038 TRACE_FUNC; |
|
1039 iMedia = aMedia; |
|
1040 } |
|
1041 |
|
1042 // ----------------------------------------------------------------------------- |
|
1043 // CSConFTP::IsCurrentDiskSpaceBelowCritical( TUint32 aFilesize ) |
|
1044 // Check is current disk space below critical level. |
|
1045 // ----------------------------------------------------------------------------- |
|
1046 // |
|
1047 TBool CSConFTP::IsCurrentDiskSpaceBelowCritical( TUint32 aFilesize ) |
|
1048 { |
|
1049 TRACE_FUNC_ENTRY; |
|
1050 LOGGER_WRITE_1( "aFilesize: %d", aFilesize ); |
|
1051 TInt drive; |
|
1052 TInt err; |
|
1053 |
|
1054 if( iCurrentDrive != KErrNotFound ) |
|
1055 { |
|
1056 drive = iCurrentDrive; |
|
1057 } |
|
1058 else |
|
1059 { |
|
1060 LOGGER_WRITE( "CSConFTP::IsCurrentDiskSpaceBelowCritical() : drive not specified, use default drive" ); |
|
1061 err = DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive ); |
|
1062 if( err ) |
|
1063 { |
|
1064 LOGGER_WRITE_1( "CSConFTP::IsCurrentDiskSpaceBelowCriticaL() : DriveInfo::GetDefaultDrive err %d", err ); |
|
1065 return ETrue; //exit |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 // check disk space |
|
1070 LOGGER_WRITE_1( "drive: %d", drive ); |
|
1071 TVolumeInfo volumeInfo; |
|
1072 err = iFs.Volume(volumeInfo, drive); |
|
1073 if( err != KErrNone ) |
|
1074 { |
|
1075 LOGGER_WRITE_1( "CSConFTP::IsCurrentDiskSpaceBelowCritical() : iFs.Volume err %d", err ); |
|
1076 LOGGER_WRITE( "CSConFTP::IsCurrentDiskSpaceBelowCritical() : End" ); |
|
1077 return ETrue; //exit |
|
1078 } |
|
1079 LOGGER_WRITE_1( "volumeInfo.iFree: %Ld", volumeInfo.iFree ); |
|
1080 TBool diskLevelCritical( EFalse ); |
|
1081 if ( volumeInfo.iFree - aFilesize <= iCriticalDiskLevel ) |
|
1082 { |
|
1083 // Can not write the data, there's not enough free space on disk. |
|
1084 diskLevelCritical = ETrue; |
|
1085 } |
|
1086 |
|
1087 LOGGER_WRITE_1( "CSConFTP::IsCurrentDiskSpaceBelowCritical() : ret %d", |
|
1088 (TInt)diskLevelCritical ); |
|
1089 return diskLevelCritical; |
|
1090 } |
|
1091 |
|
1092 // ----------------------------------------------------------------------------- |
|
1093 // CSConFTP::ReadWBXMLDataL( CBufFlat*& aBuffer ) |
|
1094 // Read received ConML protocol packet |
|
1095 // ----------------------------------------------------------------------------- |
|
1096 // |
|
1097 TInt CSConFTP::ReadWBXMLDataL( CBufFlat*& aBuffer ) |
|
1098 { |
|
1099 TRACE_FUNC_ENTRY; |
|
1100 TInt ret( KErrNone ); |
|
1101 |
|
1102 RFile file; |
|
1103 TInt fileSize; |
|
1104 |
|
1105 ret = file.Open( iFs, iTempFileName, EFileRead|EFileShareAny ); |
|
1106 CleanupClosePushL( file ); |
|
1107 if( ret == KErrNone ) |
|
1108 { |
|
1109 file.Size( fileSize ); |
|
1110 |
|
1111 delete aBuffer; |
|
1112 aBuffer = NULL; |
|
1113 |
|
1114 HBufC8* wbxmlDataBuf = HBufC8::NewLC( fileSize ); |
|
1115 TPtr8 wbxmlDataPtr = wbxmlDataBuf->Des(); |
|
1116 |
|
1117 file.Read( wbxmlDataPtr ); |
|
1118 |
|
1119 aBuffer = CBufFlat::NewL( KSConBufSize ); |
|
1120 aBuffer->ExpandL( 0, fileSize ); |
|
1121 aBuffer->Write( 0, wbxmlDataPtr ); |
|
1122 |
|
1123 CleanupStack::PopAndDestroy( wbxmlDataBuf ); |
|
1124 } |
|
1125 CleanupStack::PopAndDestroy( &file ); |
|
1126 LOGGER_WRITE_1( "CSConFTP::ReadWBXMLData( CBufFlat*& aBuffer ) : WBXML packet size: %d", fileSize ); |
|
1127 |
|
1128 LOGGER_WRITE_1( "CSConFTP::ReadWBXMLData( CBufFlat*& aBuffer ) : returned %d", ret ); |
|
1129 return ret; |
|
1130 } |
|
1131 |
|
1132 // ----------------------------------------------------------------------------- |
|
1133 // CSConFTP::DeleteTempFile() |
|
1134 // Delete OBEX stack's temp file |
|
1135 // ----------------------------------------------------------------------------- |
|
1136 // |
|
1137 void CSConFTP::DeleteTempFile() |
|
1138 { |
|
1139 TRACE_FUNC_ENTRY; |
|
1140 iFs.Delete( iTempFileName ); |
|
1141 TRACE_FUNC_EXIT; |
|
1142 } |
|
1143 |
|
1144 // ----------------------------------------------------------------------------- |
|
1145 // CSConFTP::MoveFile() |
|
1146 // Move file/folder |
|
1147 // ----------------------------------------------------------------------------- |
|
1148 // |
|
1149 TInt CSConFTP::MoveFile(const TDesC& aSource, const TDesC& aTarget) |
|
1150 { |
|
1151 TRACE_FUNC_ENTRY; |
|
1152 TInt err; |
|
1153 TFileName tmpSource; |
|
1154 TFileName tmpTarget; |
|
1155 err = GetAbsolutePath( aSource, tmpSource ); |
|
1156 if( err == KErrNone ) |
|
1157 { |
|
1158 err = GetAbsolutePath( aTarget, tmpTarget ); |
|
1159 } |
|
1160 |
|
1161 if( err == KErrNone ) |
|
1162 { |
|
1163 TInt sourceDrive; |
|
1164 TInt targetDrive; |
|
1165 |
|
1166 err = iFs.CharToDrive( tmpSource[0], sourceDrive ); |
|
1167 TInt err2 = iFs.CharToDrive( tmpTarget[0], targetDrive ); |
|
1168 |
|
1169 if( err != KErrNone || err2 != KErrNone |
|
1170 || !IsDriveVisible( sourceDrive ) |
|
1171 || !IsDriveVisible( targetDrive ) ) |
|
1172 { |
|
1173 // drive not visible to user |
|
1174 err = KErrNotFound; |
|
1175 } |
|
1176 } |
|
1177 |
|
1178 if( err == KErrNone ) |
|
1179 { |
|
1180 TRAP( err, |
|
1181 iSConFsHandler->DoCopyOrMoveFileL( tmpSource, tmpTarget, EFalse ) ); |
|
1182 } |
|
1183 |
|
1184 LOGGER_WRITE_1( "CSConFTP::MoveFile() : end, err: %d", err ); |
|
1185 return err; |
|
1186 } |
|
1187 |
|
1188 // ----------------------------------------------------------------------------- |
|
1189 // CSConFTP::CopyFile() |
|
1190 // Copy file/folder |
|
1191 // ----------------------------------------------------------------------------- |
|
1192 // |
|
1193 TInt CSConFTP::CopyFile(const TDesC& aSource, const TDesC& aTarget) |
|
1194 { |
|
1195 TRACE_FUNC_ENTRY; |
|
1196 TInt err; |
|
1197 TFileName tmpSource; |
|
1198 TFileName tmpTarget; |
|
1199 err = GetAbsolutePath( aSource, tmpSource ); |
|
1200 if (err == KErrNone) |
|
1201 { |
|
1202 err = GetAbsolutePath( aTarget, tmpTarget ); |
|
1203 } |
|
1204 |
|
1205 if( err == KErrNone ) |
|
1206 { |
|
1207 TInt sourceDrive; |
|
1208 TInt targetDrive; |
|
1209 |
|
1210 err = iFs.CharToDrive( tmpSource[0], sourceDrive ); |
|
1211 TInt err2 = iFs.CharToDrive( tmpTarget[0], targetDrive ); |
|
1212 |
|
1213 if( err != KErrNone || err2 != KErrNone |
|
1214 || !IsDriveVisible( sourceDrive ) |
|
1215 || !IsDriveVisible( targetDrive ) ) |
|
1216 { |
|
1217 // drive not visible to user |
|
1218 err = KErrNotFound; |
|
1219 } |
|
1220 } |
|
1221 |
|
1222 if (err == KErrNone) |
|
1223 { |
|
1224 TRAP( err, |
|
1225 iSConFsHandler->DoCopyOrMoveFileL( tmpSource, tmpTarget, ETrue ) ); |
|
1226 } |
|
1227 |
|
1228 LOGGER_WRITE_1( "CSConFTP::CopyFile() : end, ret: %d", err ); |
|
1229 return err; |
|
1230 } |
|
1231 |
|
1232 // ----------------------------------------------------------------------------- |
|
1233 // CSConFTP::SetReadOnly() |
|
1234 // Set read-only permissions to file or folder |
|
1235 // ----------------------------------------------------------------------------- |
|
1236 // |
|
1237 TInt CSConFTP::SetReadOnly(const TDesC& aTarget, const TBool aReadOnly) |
|
1238 { |
|
1239 TRACE_FUNC_ENTRY; |
|
1240 TInt err; |
|
1241 TFileName tmpTarget; |
|
1242 err = GetAbsolutePath( aTarget, tmpTarget ); |
|
1243 if( err != KErrNone ) |
|
1244 { |
|
1245 return err; |
|
1246 } |
|
1247 else |
|
1248 { |
|
1249 TInt targetDrive; |
|
1250 err = iFs.CharToDrive( tmpTarget[0], targetDrive ); |
|
1251 |
|
1252 if( err != KErrNone |
|
1253 || !IsDriveVisible( targetDrive ) ) |
|
1254 { |
|
1255 // drive not visible to user |
|
1256 return KErrNotFound; |
|
1257 } |
|
1258 } |
|
1259 |
|
1260 TBool isFolder(EFalse); |
|
1261 err = BaflUtils::IsFolder( iFs, tmpTarget, isFolder ); |
|
1262 if ( err == KErrNone && isFolder ) |
|
1263 { |
|
1264 tmpTarget.Append(KPathDelimiter); |
|
1265 } |
|
1266 if ( !iSConFsHandler->IsFolderVisible( tmpTarget ) ) |
|
1267 { |
|
1268 // folder is not visible to user |
|
1269 err = KErrAccessDenied; |
|
1270 } |
|
1271 else |
|
1272 { |
|
1273 if( aReadOnly ) |
|
1274 { |
|
1275 err = iFs.SetAtt( tmpTarget, KEntryAttReadOnly, KEntryAttArchive ); |
|
1276 } |
|
1277 else |
|
1278 { |
|
1279 err = iFs.SetAtt( tmpTarget, KEntryAttNormal, KEntryAttReadOnly ); |
|
1280 } |
|
1281 } |
|
1282 |
|
1283 LOGGER_WRITE_1( "CSConFTP::SetReadOnly() : ret: %d", err ); |
|
1284 return err; |
|
1285 } |
|
1286 |
|
1287 // ----------------------------------------------------------------------------- |
|
1288 // CSConFTP::SetHidden() |
|
1289 // Set hidden permissions to file or folder |
|
1290 // ----------------------------------------------------------------------------- |
|
1291 // |
|
1292 TInt CSConFTP::SetHidden( const TDesC& /*aTarget*/, const TBool /*aHidden*/ ) |
|
1293 { |
|
1294 // This is currently not supported. |
|
1295 LOGGER_WRITE("CSConFTP::SetHidden return KErrNotSupported"); |
|
1296 return KErrNotSupported; |
|
1297 } |
|
1298 |
|
1299 // ----------------------------------------------------------------------------- |
|
1300 // CSConFTP::GetAbsolutePath() |
|
1301 // Get absolute path from relative file/folder |
|
1302 // ----------------------------------------------------------------------------- |
|
1303 // |
|
1304 TInt CSConFTP::GetAbsolutePath( const TDesC& aFolderName, TDes &aFullPath ) |
|
1305 { |
|
1306 if (aFolderName.Length() == 0) |
|
1307 { |
|
1308 return KErrBadName; |
|
1309 } |
|
1310 //absolute folder path |
|
1311 if( aFolderName.Length() > 1 && aFolderName[1] == KDriveDelimiter ) |
|
1312 { |
|
1313 aFullPath.Copy( aFolderName ); |
|
1314 } |
|
1315 // relative to the root folder |
|
1316 else if( aFolderName[0] == KPathDelimiter ) |
|
1317 { |
|
1318 if( iPathName.Length() < 2 ) |
|
1319 { |
|
1320 return KErrBadName; |
|
1321 } |
|
1322 aFullPath.Copy( iPathName.Left(2) ); |
|
1323 aFullPath.Append( aFolderName ); |
|
1324 } |
|
1325 // relative to the current folder |
|
1326 else |
|
1327 { |
|
1328 aFullPath.Copy( iPathName ); |
|
1329 if( aFullPath.LocateReverse( KPathDelimiter ) != aFullPath.Length()-1 ) |
|
1330 { |
|
1331 aFullPath.Append( KPathDelimiter ); |
|
1332 } |
|
1333 aFullPath.Append( aFolderName ); |
|
1334 // no need to check internal root, because iPathName is real target. |
|
1335 } |
|
1336 |
|
1337 return KErrNone; |
|
1338 } |
|
1339 |
|
1340 // ----------------------------------------------------------------------------- |
|
1341 // CSConFTP::CSConFTP() |
|
1342 // Default constructor |
|
1343 // ----------------------------------------------------------------------------- |
|
1344 // |
|
1345 CSConFTP::CSConFTP() : iProfile( EStandard ), iCurrentDrive( KErrNotFound ) |
|
1346 { |
|
1347 } |
|
1348 |
|
1349 // ----------------------------------------------------------------------------- |
|
1350 // CSConFTP::ConstructL() |
|
1351 // Initializes member data |
|
1352 // ----------------------------------------------------------------------------- |
|
1353 // |
|
1354 void CSConFTP::ConstructL() |
|
1355 { |
|
1356 TRACE_FUNC_ENTRY; |
|
1357 |
|
1358 iBuffer = CBufFlat::NewL( KSConBufSize ); |
|
1359 User::LeaveIfError( iFs.Connect() ); |
|
1360 iSConFsHandler = CSConFsHandler::NewL( iFs ); |
|
1361 iSConInboxHandler = CSConInboxHandler::NewL(); |
|
1362 |
|
1363 CRepository* repository = CRepository::NewLC( KCRUidDiskLevel ); |
|
1364 User::LeaveIfError( repository->Get( KDiskCriticalThreshold, iCriticalDiskLevel ) ); |
|
1365 CleanupStack::PopAndDestroy( repository ); |
|
1366 // inlcude package size |
|
1367 iCriticalDiskLevel += KPackageSize; |
|
1368 LOGGER_WRITE_1( "criticalLevel: %d", iCriticalDiskLevel ); |
|
1369 |
|
1370 TRACE_FUNC_EXIT; |
|
1371 } |
|
1372 |
|
1373 // ----------------------------------------------------------------------------- |
|
1374 // CSConFTP::GetVolumeNameL() |
|
1375 // Get volume name |
|
1376 // ----------------------------------------------------------------------------- |
|
1377 // |
|
1378 TInt CSConFTP::GetVolumeNameL(const TInt aDriveNumber, TDes8& aVolumeName) |
|
1379 { |
|
1380 TRACE_FUNC_ENTRY; |
|
1381 TVolumeInfo volumeInfo; |
|
1382 TInt ret = iFs.Volume( volumeInfo, aDriveNumber ); |
|
1383 |
|
1384 if ( ret == KErrNone) |
|
1385 { |
|
1386 CnvUtfConverter::ConvertFromUnicodeToUtf8( aVolumeName, |
|
1387 volumeInfo.iName ); |
|
1388 //Replace special characters |
|
1389 for( TInt i = 0; i < aVolumeName.Length(); i++ ) |
|
1390 { |
|
1391 switch( aVolumeName[i] ) |
|
1392 { |
|
1393 case '&': |
|
1394 aVolumeName.Delete( i, 1 ); |
|
1395 aVolumeName.Insert( i, KReplace1 ); |
|
1396 break; |
|
1397 case '<': |
|
1398 aVolumeName.Delete( i, 1 ); |
|
1399 aVolumeName.Insert( i, KReplace2 ); |
|
1400 break; |
|
1401 case '>': |
|
1402 aVolumeName.Delete( i, 1 ); |
|
1403 aVolumeName.Insert( i, KReplace3 ); |
|
1404 break; |
|
1405 case '"': |
|
1406 aVolumeName.Delete( i, 1 ); |
|
1407 aVolumeName.Insert( i, KReplace4 ); |
|
1408 break; |
|
1409 case '\'': |
|
1410 aVolumeName.Delete( i, 1 ); |
|
1411 aVolumeName.Insert( i, KReplace5 ); |
|
1412 break; |
|
1413 default: |
|
1414 break; |
|
1415 } |
|
1416 } |
|
1417 |
|
1418 //No name |
|
1419 if( aVolumeName.Length() == 0 ) |
|
1420 { |
|
1421 LOGGER_WRITE( "Volume has no name, use default localized name" ); |
|
1422 //Read memory string and convert it |
|
1423 TFileName file( KSConResourceName ); |
|
1424 |
|
1425 BaflUtils::NearestLanguageFile( iFs, file ); |
|
1426 |
|
1427 CStringResourceReader* reader = CStringResourceReader::NewL( file ); |
|
1428 CleanupStack::PushL( reader ); |
|
1429 TUint driveStatus; |
|
1430 User::LeaveIfError( DriveInfo::GetDriveStatus( iFs, aDriveNumber, driveStatus ) ); |
|
1431 if( driveStatus & DriveInfo::EDriveRemovable ) |
|
1432 { |
|
1433 // read default MMC name |
|
1434 CnvUtfConverter::ConvertFromUnicodeToUtf8( aVolumeName, |
|
1435 reader->ReadResourceString( R_SECON_VALUE_MMC ) ); |
|
1436 } |
|
1437 else |
|
1438 { |
|
1439 // read default DEV name |
|
1440 CnvUtfConverter::ConvertFromUnicodeToUtf8( aVolumeName, |
|
1441 reader->ReadResourceString( R_SECON_VALUE_DEVICE ) ); |
|
1442 } |
|
1443 CleanupStack::PopAndDestroy( reader ); |
|
1444 } |
|
1445 } |
|
1446 LOGGER_WRITE_1("GetVolumeNameL returned: %d", ret); |
|
1447 return ret; |
|
1448 } |
|
1449 |
|
1450 // ----------------------------------------------------------------------------- |
|
1451 // CSConFTP::IsDriveVisible() |
|
1452 // Check is drive visible for user |
|
1453 // ----------------------------------------------------------------------------- |
|
1454 // |
|
1455 TBool CSConFTP::IsDriveVisible( const TInt aDriveNumber ) |
|
1456 { |
|
1457 TUint driveStatus; |
|
1458 TInt err = DriveInfo::GetDriveStatus( iFs, aDriveNumber, driveStatus); |
|
1459 if( err ) |
|
1460 { |
|
1461 LOGGER_WRITE_1( "CSConFTP::IsDriveVisible() : DriveInfo::GetDriveStatus err: %d", err ); |
|
1462 return EFalse; |
|
1463 } |
|
1464 if( driveStatus & DriveInfo::EDriveRemote ) |
|
1465 { |
|
1466 LOGGER_WRITE( "CSConFTP::IsDriveVisible() : remote drive" ); |
|
1467 return EFalse; |
|
1468 } |
|
1469 if( !(driveStatus & DriveInfo::EDriveUserVisible) ) |
|
1470 { |
|
1471 LOGGER_WRITE( "CSConFTP::IsDriveVisible() : not visible" ); |
|
1472 return EFalse; |
|
1473 } |
|
1474 if( !(driveStatus & DriveInfo::EDrivePresent ) ) |
|
1475 { |
|
1476 LOGGER_WRITE( "CSConFTP::IsDriveVisible() : not present" ); |
|
1477 return EFalse; |
|
1478 } |
|
1479 if( driveStatus & DriveInfo::EDriveCorrupt ) |
|
1480 { |
|
1481 LOGGER_WRITE( "CSConFTP::IsDriveVisible() : corrupted" ); |
|
1482 return EFalse; |
|
1483 } |
|
1484 else |
|
1485 { |
|
1486 return ETrue; |
|
1487 } |
|
1488 } |
|
1489 |
|
1490 // ----------------------------------------------------------------------------- |
|
1491 // CSConFTP::UpdateDriveTypeInfoL() |
|
1492 // Test is current volume still ok. |
|
1493 // ----------------------------------------------------------------------------- |
|
1494 // |
|
1495 TBool CSConFTP::IsCurrentVolumeOK() |
|
1496 { |
|
1497 if( iCurrentDrive == KErrNotFound ) |
|
1498 { |
|
1499 LOGGER_WRITE( "CSConFTP::IsCurrentVolumeOK() : not set" ); |
|
1500 return EFalse; |
|
1501 } |
|
1502 |
|
1503 TUint driveStatus; |
|
1504 TInt err = DriveInfo::GetDriveStatus( iFs, iCurrentDrive, driveStatus); |
|
1505 if( err ) |
|
1506 { |
|
1507 LOGGER_WRITE_1( "CSConFTP::IsCurrentVolumeOK() : DriveInfo::GetDriveStatus err: %d", err ); |
|
1508 return EFalse; |
|
1509 } |
|
1510 if( !(driveStatus & DriveInfo::EDrivePresent )) |
|
1511 { |
|
1512 LOGGER_WRITE( "CSConFTP::IsCurrentVolumeOK() : not present" ); |
|
1513 return EFalse; |
|
1514 } |
|
1515 if( driveStatus & DriveInfo::EDriveCorrupt ) |
|
1516 { |
|
1517 LOGGER_WRITE( "CSConFTP::IsCurrentVolumeOK() : corrupted" ); |
|
1518 return EFalse; |
|
1519 } |
|
1520 else |
|
1521 { |
|
1522 return ETrue; |
|
1523 } |
|
1524 } |
|
1525 |
|
1526 // ----------------------------------------------------------------------------- |
|
1527 // CSConFTP::UpdateDriveTypeInfoL() |
|
1528 // Updates drive information (iCurrentDrive and iCurrentDriveTypeNumber) |
|
1529 // ----------------------------------------------------------------------------- |
|
1530 // |
|
1531 void CSConFTP::UpdateDriveTypeInfoL() |
|
1532 { |
|
1533 TRACE_FUNC_ENTRY; |
|
1534 TInt driveNumber; |
|
1535 iCurrentDriveTypeNumber = 0; |
|
1536 |
|
1537 if( iPathName.Length() == 0 ) |
|
1538 { |
|
1539 LOGGER_WRITE( "CSConFTP::UpdateDriveTypeInfoL() : drive not specified" ); |
|
1540 iCurrentDrive = KErrNotFound; |
|
1541 return; |
|
1542 } |
|
1543 |
|
1544 User::LeaveIfError( iFs.CharToDrive(iPathName[0], driveNumber) ); |
|
1545 iCurrentDrive = driveNumber; |
|
1546 |
|
1547 TUint driveStatus; |
|
1548 User::LeaveIfError( DriveInfo::GetDriveStatus( iFs, iCurrentDrive, driveStatus ) ); |
|
1549 // if true, search internal drives, else search removable drives |
|
1550 TBool searchInternalDrives = (driveStatus & DriveInfo::EDriveInternal); |
|
1551 |
|
1552 TInt driveCount; |
|
1553 TDriveList driveList; |
|
1554 |
|
1555 User::LeaveIfError( DriveInfo::GetUserVisibleDrives( iFs, driveList, driveCount ) ); |
|
1556 |
|
1557 for( TInt i = EDriveA; i <= iCurrentDrive; i++ ) |
|
1558 { |
|
1559 if( driveList[i] ) |
|
1560 { |
|
1561 TUint driveStatus; |
|
1562 User::LeaveIfError( DriveInfo::GetDriveStatus( iFs, i, driveStatus ) ); |
|
1563 |
|
1564 if( !(driveStatus & DriveInfo::EDrivePresent ) |
|
1565 || driveStatus & DriveInfo::EDriveCorrupt ) |
|
1566 { |
|
1567 LOGGER_WRITE( "not present or corrupted" ); |
|
1568 continue; |
|
1569 } |
|
1570 |
|
1571 if( driveStatus & DriveInfo::EDriveInternal ) |
|
1572 { |
|
1573 if( searchInternalDrives ) |
|
1574 { |
|
1575 iCurrentDriveTypeNumber++; |
|
1576 } |
|
1577 } |
|
1578 else if( driveStatus & DriveInfo::EDriveRemovable ) |
|
1579 { |
|
1580 if( !searchInternalDrives ) |
|
1581 { |
|
1582 iCurrentDriveTypeNumber++; |
|
1583 } |
|
1584 } |
|
1585 } |
|
1586 } |
|
1587 TRACE_FUNC_EXIT; |
|
1588 } |
|
1589 |
|
1590 // End of file |
|
1591 |