21 #include <mtp/mmtpstoragemgr.h> |
21 #include <mtp/mmtpstoragemgr.h> |
22 |
22 |
23 #include "cmtprequestchecker.h" |
23 #include "cmtprequestchecker.h" |
24 #include "cmtpfsexclusionmgr.h" |
24 #include "cmtpfsexclusionmgr.h" |
25 #include "cmtpfsentrycache.h" |
25 #include "cmtpfsentrycache.h" |
|
26 #include "mtpdebug.h" |
|
27 #include "OstTraceDefinitions.h" |
|
28 #ifdef OST_TRACE_COMPILER_IN_USE |
|
29 #include "cmtprequestcheckerTraces.h" |
|
30 #endif |
|
31 |
26 |
32 |
27 static const TInt KMTPRequestCheckerHandleGranularity = 2; |
33 static const TInt KMTPRequestCheckerHandleGranularity = 2; |
28 __FLOG_STMT(_LIT8(KComponent,"MTPRequestChecker");) |
|
29 |
34 |
30 /** |
35 /** |
31 Two-phase construction method |
36 Two-phase construction method |
32 @param aFramework The data provider framework |
37 @param aFramework The data provider framework |
33 @param aConnection The connection object |
38 @param aConnection The connection object |
45 /** |
50 /** |
46 Destructor |
51 Destructor |
47 */ |
52 */ |
48 EXPORT_C CMTPRequestChecker::~CMTPRequestChecker() |
53 EXPORT_C CMTPRequestChecker::~CMTPRequestChecker() |
49 { |
54 { |
|
55 OstTraceFunctionEntry0( CMTPREQUESTCHECKER_CMTPREQUESTCHECKER_ENTRY ); |
50 iDpSingletons.Close(); |
56 iDpSingletons.Close(); |
51 iHandles.Close(); |
57 iHandles.Close(); |
52 iObjectArray.ResetAndDestroy(); |
58 iObjectArray.ResetAndDestroy(); |
53 __FLOG_CLOSE; |
59 OstTraceFunctionExit0( CMTPREQUESTCHECKER_CMTPREQUESTCHECKER_EXIT ); |
54 } |
60 } |
55 |
61 |
56 /** |
62 /** |
57 Verfiy the request. It check the request header first (session id and transaction code), and check for special values, last |
63 Verfiy the request. It check the request header first (session id and transaction code), and check for special values, last |
58 it iterates through the verification elements for checking individul parameters in the request |
64 it iterates through the verification elements for checking individul parameters in the request |
204 @param aElementInfo Element info array to be checked against. |
210 @param aElementInfo Element info array to be checked against. |
205 @return repsonse code to return to initiator |
211 @return repsonse code to return to initiator |
206 */ |
212 */ |
207 TMTPResponseCode CMTPRequestChecker::VerifyObjectHandleL(TUint32 aHandle, const TMTPRequestElementInfo& aElementInfo) |
213 TMTPResponseCode CMTPRequestChecker::VerifyObjectHandleL(TUint32 aHandle, const TMTPRequestElementInfo& aElementInfo) |
208 { |
214 { |
209 __FLOG_VA((_L8("VerifyObjectHandleL entry with handle 0x%08X"), aHandle)); |
215 OstTraceFunctionEntry0( CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL_ENTRY ); |
|
216 OstTrace1( TRACE_NORMAL, CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL, "with handle 0x%08X", aHandle ); |
210 TMTPResponseCode ret = EMTPRespCodeOK; |
217 TMTPResponseCode ret = EMTPRespCodeOK; |
211 |
218 |
212 CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC()); |
219 CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC()); |
213 TBool result(iFramework.ObjectMgr().ObjectL(aHandle, *object)); |
220 TBool result(iFramework.ObjectMgr().ObjectL(aHandle, *object)); |
214 iObjectArray.AppendL(object); |
221 iObjectArray.AppendL(object); |
219 if (result) |
226 if (result) |
220 { |
227 { |
221 TUint storageID = object->Uint(CMTPObjectMetaData::EStorageId); |
228 TUint storageID = object->Uint(CMTPObjectMetaData::EStorageId); |
222 if(!iFramework.StorageMgr().ValidStorageId(storageID)) |
229 if(!iFramework.StorageMgr().ValidStorageId(storageID)) |
223 { |
230 { |
|
231 OstTraceFunctionExit0( CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL_EXIT ); |
224 return EMTPRespCodeInvalidObjectHandle; |
232 return EMTPRespCodeInvalidObjectHandle; |
225 } |
233 } |
226 |
234 |
227 CMTPStorageMetaData* storageMetaData = (CMTPStorageMetaData *)& iFramework.StorageMgr().StorageL(storageID); |
235 CMTPStorageMetaData* storageMetaData = (CMTPStorageMetaData *)& iFramework.StorageMgr().StorageL(storageID); |
228 if (storageMetaData->Uint(CMTPStorageMetaData::EStorageSystemType) != CMTPStorageMetaData::ESystemTypeDefaultFileSystem) |
236 if (storageMetaData->Uint(CMTPStorageMetaData::EStorageSystemType) != CMTPStorageMetaData::ESystemTypeDefaultFileSystem) |
229 { |
237 { |
|
238 OstTraceFunctionExit0( DUP1_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL_EXIT ); |
230 return ret; |
239 return ret; |
231 } |
240 } |
232 |
241 |
233 const TDesC& suid(object->DesC(CMTPObjectMetaData::ESuid)); |
242 const TDesC& suid(object->DesC(CMTPObjectMetaData::ESuid)); |
234 TEntry entry; |
243 TEntry entry; |
236 |
245 |
237 if ( (object->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation) && |
246 if ( (object->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation) && |
238 (object->Uint(CMTPObjectMetaData::EFormatSubCode) != EMTPAssociationTypeGenericFolder ) ) |
247 (object->Uint(CMTPObjectMetaData::EFormatSubCode) != EMTPAssociationTypeGenericFolder ) ) |
239 { |
248 { |
240 // Special association type .. not always present on the filesystem. |
249 // Special association type .. not always present on the filesystem. |
|
250 OstTraceFunctionExit0( DUP2_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL_EXIT ); |
241 return ret; |
251 return ret; |
242 } |
252 } |
243 else |
253 else |
244 { |
254 { |
245 if ( err != KErrNone ) |
255 if ( err != KErrNone ) |
246 { |
256 { |
247 if( (iDpSingletons.CopyingBigFileCache().TargetHandle() == aHandle) && |
257 if( (iDpSingletons.CopyingBigFileCache().TargetHandle() == aHandle) && |
248 (iDpSingletons.CopyingBigFileCache().IsOnGoing())) |
258 (iDpSingletons.CopyingBigFileCache().IsOnGoing())) |
249 { |
259 { |
250 // The object is being copied, it is not created in fs yet. Use its cache entry for check |
260 // The object is being copied, it is not created in fs yet. Use its cache entry for check |
251 __FLOG(_L8("VerifyObjectHandleL - The object is being copied, use its cache entry for check")); |
261 OstTrace0( TRACE_NORMAL, DUP1_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL, |
|
262 "VerifyObjectHandleL - The object is being copied, use its cache entry for check" ); |
252 entry = iDpSingletons.CopyingBigFileCache().FileEntry(); |
263 entry = iDpSingletons.CopyingBigFileCache().FileEntry(); |
253 err = KErrNone; |
264 err = KErrNone; |
254 } |
265 } |
255 else if( (iDpSingletons.MovingBigFileCache().TargetHandle() == aHandle) && |
266 else if( (iDpSingletons.MovingBigFileCache().TargetHandle() == aHandle) && |
256 (iDpSingletons.MovingBigFileCache().IsOnGoing())) |
267 (iDpSingletons.MovingBigFileCache().IsOnGoing())) |
257 { |
268 { |
258 // The object is being moved, it is not created in fs yet. Use its cache entry for check |
269 // The object is being moved, it is not created in fs yet. Use its cache entry for check |
259 __FLOG(_L8("VerifyObjectHandleL - The object is being moved, use its cache entry for check")); |
270 OstTrace0( TRACE_NORMAL, DUP2_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL, |
|
271 "VerifyObjectHandleL - The object is being moved, use its cache entry for check" ); |
260 entry = iDpSingletons.MovingBigFileCache().FileEntry(); |
272 entry = iDpSingletons.MovingBigFileCache().FileEntry(); |
261 err = KErrNone; |
273 err = KErrNone; |
262 } |
274 } |
263 } |
275 } |
264 User::LeaveIfError(err); |
276 LEAVEIFERROR(err, |
|
277 OstTraceExt2( TRACE_ERROR, DUP5_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL, |
|
278 "Can't get entry details for %S even after error handling! error code %d", suid, err)); |
265 } |
279 } |
266 |
280 |
267 if (aElementInfo.iElementAttr & EMTPElementAttrWrite) |
281 if (aElementInfo.iElementAttr & EMTPElementAttrWrite) |
268 { |
282 { |
269 if (entry.IsReadOnly()) |
283 if (entry.IsReadOnly()) |
295 } |
309 } |
296 |
310 |
297 } |
311 } |
298 else |
312 else |
299 { |
313 { |
300 __FLOG(_L8("Object does not exist.")); |
314 OstTrace0( TRACE_WARNING, DUP3_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL, "Object does not exist." ); |
301 ret = EMTPRespCodeInvalidObjectHandle; |
315 ret = EMTPRespCodeInvalidObjectHandle; |
302 } |
316 } |
303 __FLOG_VA((_L8("VerifyObjectHandleL exit with repsonse code 0x%04X"), ret)); |
317 OstTrace1( TRACE_WARNING, DUP4_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL, "with repsonse code 0x%04X", ret ); |
|
318 OstTraceFunctionExit0( DUP3_CMTPREQUESTCHECKER_VERIFYOBJECTHANDLEL_EXIT ); |
304 return ret; |
319 return ret; |
305 } |
320 } |
306 |
321 |
307 /** |
322 /** |
308 Check the storage id parameter in the request, read/write attributes |
323 Check the storage id parameter in the request, read/write attributes |
327 TInt drive(mgr.DriveNumber(aStorageId)); |
342 TInt drive(mgr.DriveNumber(aStorageId)); |
328 // StorageIDs which are not system owned do not correspond to drives. |
343 // StorageIDs which are not system owned do not correspond to drives. |
329 if (drive != KErrNotFound) |
344 if (drive != KErrNotFound) |
330 { |
345 { |
331 TDriveInfo info; |
346 TDriveInfo info; |
332 User::LeaveIfError(iFramework.Fs().Drive(info, drive)); |
347 LEAVEIFERROR(iFramework.Fs().Drive(info, drive), |
|
348 OstTrace1( TRACE_ERROR, CMTPREQUESTCHECKER_VERIFYSTORAGEIDL, "Gets information about drive %d failed!", drive)); |
333 if (info.iType == EMediaNotPresent) |
349 if (info.iType == EMediaNotPresent) |
334 { |
350 { |
335 /* |
351 /* |
336 Race conditions between media ejection and request processing |
352 Race conditions between media ejection and request processing |
337 may result in a previously valid storage ID no longer being |
353 may result in a previously valid storage ID no longer being |
411 :iFramework(aFramework), |
427 :iFramework(aFramework), |
412 iConnection(aConnection), |
428 iConnection(aConnection), |
413 iHandles(KMTPRequestCheckerHandleGranularity), |
429 iHandles(KMTPRequestCheckerHandleGranularity), |
414 iObjectArray(KMTPRequestCheckerHandleGranularity) |
430 iObjectArray(KMTPRequestCheckerHandleGranularity) |
415 { |
431 { |
416 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
417 } |
432 } |
418 |
433 |
419 /** |
434 /** |
420 Second phase constructor |
435 Second phase constructor |
421 */ |
436 */ |
422 void CMTPRequestChecker::ConstructL() |
437 void CMTPRequestChecker::ConstructL() |
423 { |
438 { |
|
439 OstTraceFunctionEntry0( CMTPREQUESTCHECKER_CONSTRUCTL_ENTRY ); |
424 iDpSingletons.OpenL(iFramework); |
440 iDpSingletons.OpenL(iFramework); |
425 } |
441 OstTraceFunctionExit0( CMTPREQUESTCHECKER_CONSTRUCTL_EXIT ); |
426 |
442 } |
427 |
443 |
|
444 |