52 iFramework( aFramework ), |
51 iFramework( aFramework ), |
53 iConnection( aConnection ), |
52 iConnection( aConnection ), |
54 iHandles( KMTPRequestCheckerHandleGranularity ), |
53 iHandles( KMTPRequestCheckerHandleGranularity ), |
55 iObjectArray( KMTPRequestCheckerHandleGranularity ) |
54 iObjectArray( KMTPRequestCheckerHandleGranularity ) |
56 { |
55 { |
57 |
56 // Do nothing |
58 } |
57 } |
59 |
58 |
60 // ----------------------------------------------------------------------------- |
59 // ----------------------------------------------------------------------------- |
61 // CRequestChecker::ConstructL |
60 // CRequestChecker::ConstructL |
62 // Two-phase construction method |
61 // Two-phase construction method |
63 // ----------------------------------------------------------------------------- |
62 // ----------------------------------------------------------------------------- |
64 // |
63 // |
65 void CRequestChecker::ConstructL() |
64 void CRequestChecker::ConstructL() |
66 { |
65 { |
67 |
66 // Do nothing |
68 } |
67 } |
69 |
68 |
70 // ----------------------------------------------------------------------------- |
69 // ----------------------------------------------------------------------------- |
71 // CRequestChecker::~CRequestChecker |
70 // CRequestChecker::~CRequestChecker |
72 // Destructor |
71 // Destructor |
78 iObjectArray.ResetAndDestroy(); |
77 iObjectArray.ResetAndDestroy(); |
79 } |
78 } |
80 |
79 |
81 // ----------------------------------------------------------------------------- |
80 // ----------------------------------------------------------------------------- |
82 // CRequestChecker::VerifyRequestL |
81 // CRequestChecker::VerifyRequestL |
83 // Verfiy the request |
82 // Verify the request |
84 // ----------------------------------------------------------------------------- |
83 // ----------------------------------------------------------------------------- |
85 // |
84 // |
86 TMTPResponseCode CRequestChecker::VerifyRequestL( const TMTPTypeRequest& aRequest, |
85 TMTPResponseCode CRequestChecker::VerifyRequestL( const TMTPTypeRequest& aRequest, |
87 TInt aCount, |
86 TInt aCount, |
88 const TMTPRequestElementInfo* aElementInfo ) |
87 const TMTPRequestElementInfo* aElementInfo ) |
89 { |
88 { |
90 TMTPResponseCode result = EMTPRespCodeOK; |
89 TMTPResponseCode result = EMTPRespCodeOK; |
91 iHandles.Close(); |
90 iHandles.Close(); |
92 iObjectArray.ResetAndDestroy(); |
91 iObjectArray.ResetAndDestroy(); |
93 |
92 |
94 result = CheckRequestHeader( aRequest ); |
93 result = CheckRequestHeader( aRequest ); |
95 |
94 |
96 for ( TInt i = 0; i < aCount && EMTPRespCodeOK == result; i++ ) |
95 for ( TInt i = 0; i < aCount && EMTPRespCodeOK == result; i++ ) |
97 { |
96 { |
98 TUint32 parameter = aRequest.Uint32( aElementInfo[i].iElementIndex ); |
97 TUint32 parameter = aRequest.Uint32( aElementInfo[i].iElementIndex ); |
99 PRINT3( _L( "MM MTP <> CRequestChecker parameter %d/%d = %d" ), |
98 PRINT3( _L( "MM MTP <> CRequestChecker parameter %d/%d = %d" ), |
100 i + 1, aCount, parameter ); |
99 i + 1, |
101 |
100 aCount, |
|
101 parameter ); |
|
102 |
102 if ( !IsSpecialValue( parameter, aElementInfo[i] ) ) |
103 if ( !IsSpecialValue( parameter, aElementInfo[i] ) ) |
103 { |
104 { |
104 switch ( aElementInfo[i].iElementType ) |
105 switch ( aElementInfo[i].iElementType ) |
105 { |
106 { |
106 case EMTPElementTypeSessionID: |
107 case EMTPElementTypeSessionID: |
196 else if ( !iConnection.SessionWithMTPIdExists( sessionId ) ) |
197 else if ( !iConnection.SessionWithMTPIdExists( sessionId ) ) |
197 { |
198 { |
198 ret = EMTPRespCodeSessionNotOpen; |
199 ret = EMTPRespCodeSessionNotOpen; |
199 } |
200 } |
200 } |
201 } |
201 |
202 |
202 return ret; |
203 return ret; |
203 } |
204 } |
204 |
205 |
205 // ----------------------------------------------------------------------------- |
206 // ----------------------------------------------------------------------------- |
206 // CRequestChecker::VerifySessionId |
207 // CRequestChecker::VerifySessionId |
207 // Check the session id in the request parameter (NOTE the session id is different from the one in the request header), |
208 // Check the session id in the request parameter (NOTE the session id is different from the one in the request header), |
208 // this usually only applies to the OpenSession request |
209 // this usually only applies to the OpenSession request |
209 // ----------------------------------------------------------------------------- |
210 // ----------------------------------------------------------------------------- |
210 // |
211 // |
211 TMTPResponseCode CRequestChecker::VerifySessionId( TUint32 aSessionId, |
212 TMTPResponseCode CRequestChecker::VerifySessionId( TUint32 aSessionId, |
212 const TMTPRequestElementInfo& /*aElementInfo*/ ) const |
213 const TMTPRequestElementInfo& /*aElementInfo*/ ) const |
213 { |
214 { |
214 TMTPResponseCode ret = EMTPRespCodeOK; |
215 TMTPResponseCode ret = EMTPRespCodeOK; |
215 |
216 |
216 if ( aSessionId != 0 ) |
217 if ( aSessionId != 0 ) |
217 { |
218 { |
222 } |
223 } |
223 else |
224 else |
224 { |
225 { |
225 ret = EMTPRespCodeInvalidParameter; |
226 ret = EMTPRespCodeInvalidParameter; |
226 } |
227 } |
227 |
228 |
228 return ret; |
229 return ret; |
229 } |
230 } |
230 |
231 |
231 // ----------------------------------------------------------------------------- |
232 // ----------------------------------------------------------------------------- |
232 // CRequestChecker::VerifyObjectHandleL |
233 // CRequestChecker::VerifyObjectHandleL |
233 // Check the object handle in the request parameter, whether the handle is in the object store, |
234 // Check the object handle in the request parameter, whether the handle is in the object store, |
234 // read/write, file/dir |
235 // read/write, file/dir |
235 // ----------------------------------------------------------------------------- |
236 // ----------------------------------------------------------------------------- |
236 // |
237 // |
237 TMTPResponseCode CRequestChecker::VerifyObjectHandleL( TUint32 aHandle, |
238 TMTPResponseCode CRequestChecker::VerifyObjectHandleL( TUint32 aHandle, |
238 const TMTPRequestElementInfo& aElementInfo ) |
239 const TMTPRequestElementInfo& aElementInfo ) |
239 { |
240 { |
240 PRINT1( _L("MM MTP => CRequestChecker::VerifyObjectHandleL aHandle = 0x%x"), aHandle ); |
241 PRINT1( _L("MM MTP => CRequestChecker::VerifyObjectHandleL aHandle = 0x%x"), aHandle ); |
241 TMTPResponseCode ret = EMTPRespCodeOK; |
242 TMTPResponseCode ret = EMTPRespCodeOK; |
242 |
243 |
243 CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC() ); |
244 CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC() ); |
250 if ( result ) |
251 if ( result ) |
251 { |
252 { |
252 const TDesC& suid( object->DesC( CMTPObjectMetaData::ESuid ) ); |
253 const TDesC& suid( object->DesC( CMTPObjectMetaData::ESuid ) ); |
253 TEntry entry; |
254 TEntry entry; |
254 TInt err = iFramework.Fs().Entry( suid, entry ); |
255 TInt err = iFramework.Fs().Entry( suid, entry ); |
255 |
256 |
256 if ( object->Uint( CMTPObjectMetaData::EFormatCode ) == EMTPFormatCodeAssociation ) |
257 if ( err == KErrNotFound ) |
257 // && ( object->Uint( CMTPObjectMetaData::EFormatSubCode ) == EMTPAssociationTypeGenericFolder ) ) |
258 { |
258 { |
259 iFramework.ObjectMgr().RemoveObjectL( suid ); |
259 // Special association type .. not always present on the filesystem. |
260 // TODO: workaround for abstractalbumart |
260 return ret; |
261 // ret = EMTPRespCodeInvalidObjectHandle; |
261 } |
262 } |
262 else |
263 else if ( err != KErrNone ) |
263 { |
264 ret = EMTPRespCodeGeneralError; |
264 User::LeaveIfError( err ); |
265 else if ( object->Uint( CMTPObjectMetaData::EFormatCode ) != EMTPFormatCodeAssociation ) |
265 |
266 { |
266 if ( iFramework.ObjectMgr().ObjectOwnerId( aHandle ) != iFramework.DataProviderId() ) |
267 if ( iFramework.ObjectMgr().ObjectOwnerId( aHandle ) != iFramework.DataProviderId() ) |
267 { |
|
268 PRINT( _L(" ewrwe ret = EMTPRespCodeInvalidObjectHandle;")); |
|
269 ret = EMTPRespCodeInvalidObjectHandle; |
268 ret = EMTPRespCodeInvalidObjectHandle; |
270 } |
269 |
271 } |
270 if ( ( aElementInfo.iElementAttr & EMTPElementAttrWrite ) && entry.IsReadOnly() ) |
272 |
|
273 if ( aElementInfo.iElementAttr & EMTPElementAttrWrite ) |
|
274 { |
|
275 if ( entry.IsReadOnly() ) |
|
276 { |
|
277 ret = EMTPRespCodeObjectWriteProtected; |
271 ret = EMTPRespCodeObjectWriteProtected; |
278 } |
272 |
279 } |
273 if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrFile ) && entry.IsDir() ) |
280 |
|
281 //((EMTPRespCodeOK == ret) && (aElementInfo.iElementAttr & EMTPElementAttrFileOrDir)) is |
|
282 // covered implicitly here, EMTPRespCodeOK will be returned. It is a valid case for an object to be either a folder or file |
|
283 // for certain operation's request parameter, for instance the first parameter of copyObject or |
|
284 // moveObject can be either a file or a directory. |
|
285 |
|
286 // Other cases. |
|
287 if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrFile) ) |
|
288 { |
|
289 if ( entry.IsDir() ) |
|
290 { |
|
291 ret = EMTPRespCodeInvalidObjectHandle; |
274 ret = EMTPRespCodeInvalidObjectHandle; |
292 } |
275 |
293 } |
276 if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrDir ) && !entry.IsDir() ) |
294 |
|
295 if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrDir ) ) |
|
296 { |
|
297 if (!entry.IsDir()) |
|
298 { |
|
299 ret = EMTPRespCodeInvalidParentObject; |
277 ret = EMTPRespCodeInvalidParentObject; |
300 } |
|
301 } |
278 } |
302 } |
279 } |
303 else |
280 else |
304 { |
|
305 PRINT( _L( "MM MTP <> CRequestChecker::VerifyObjectHandleL, Object does not exist." ) ); |
|
306 ret = EMTPRespCodeInvalidObjectHandle; |
281 ret = EMTPRespCodeInvalidObjectHandle; |
307 } |
282 |
308 PRINT1( _L( "MM MTP <= CRequestChecker::VerifyObjectHandleL ret = 0x%x" ), ret ); |
283 PRINT1( _L( "MM MTP <= CRequestChecker::VerifyObjectHandleL ret = 0x%x" ), ret ); |
309 |
284 |
310 return ret; |
285 return ret; |
311 } |
286 } |
312 |
287 |
313 // ----------------------------------------------------------------------------- |
288 // ----------------------------------------------------------------------------- |
314 // CRequestChecker::VerifyStorageIdL |
289 // CRequestChecker::VerifyStorageIdL |
315 // Check the storage id parameter in the request, read/write attributes |
290 // Check the storage id parameter in the request, read/write attributes |
316 // ----------------------------------------------------------------------------- |
291 // ----------------------------------------------------------------------------- |
317 // |
292 // |
318 TMTPResponseCode CRequestChecker::VerifyStorageIdL( TUint32 aStorageId, |
293 TMTPResponseCode CRequestChecker::VerifyStorageIdL( TUint32 aStorageId, |
319 const TMTPRequestElementInfo& aElementInfo ) const |
294 const TMTPRequestElementInfo& aElementInfo ) const |
320 { |
295 { |
321 MMTPStorageMgr& mgr( iFramework.StorageMgr() ); |
296 MMTPStorageMgr& mgr( iFramework.StorageMgr() ); |
322 TMTPResponseCode ret( EMTPRespCodeOK ); |
297 TMTPResponseCode ret( EMTPRespCodeOK ); |
323 if ( !mgr.ValidStorageId( aStorageId ) ) |
298 if ( !mgr.ValidStorageId( aStorageId ) ) |
324 { |
299 { |
355 ret = EMTPRespCodeStoreReadOnly; |
330 ret = EMTPRespCodeStoreReadOnly; |
356 } |
331 } |
357 } |
332 } |
358 } |
333 } |
359 } |
334 } |
360 |
335 |
361 return ret; |
336 return ret; |
362 } |
337 } |
363 |
338 |
364 // ----------------------------------------------------------------------------- |
339 // ----------------------------------------------------------------------------- |
365 // CRequestChecker::VerifyFormatCode |
340 // CRequestChecker::VerifyFormatCode |
366 // Check the format code parameter in the request |
341 // Check the format code parameter in the request |
367 // ----------------------------------------------------------------------------- |
342 // ----------------------------------------------------------------------------- |
368 // |
343 // |
369 TMTPResponseCode CRequestChecker::VerifyFormatCode( TUint32 aFormatCode, |
344 TMTPResponseCode CRequestChecker::VerifyFormatCode( TUint32 aFormatCode, |
370 const TMTPRequestElementInfo& aElementInfo ) const |
345 const TMTPRequestElementInfo& aElementInfo ) const |
371 { |
346 { |
372 PRINT1( _L( "MM MTP => CRequestChecker::VerifyFormatCode aFormatCode = 0x%x" ), aFormatCode ); |
347 PRINT1( _L( "MM MTP => CRequestChecker::VerifyFormatCode aFormatCode = 0x%x" ), aFormatCode ); |
373 TMTPResponseCode ret = EMTPRespCodeInvalidObjectFormatCode; |
348 TMTPResponseCode ret = EMTPRespCodeInvalidObjectFormatCode; |
374 |
349 |
375 if ( aElementInfo.iElementAttr == EMTPElementAttrFormatEnums ) |
350 if ( aElementInfo.iElementAttr == EMTPElementAttrFormatEnums ) |
393 ret = EMTPRespCodeOK; |
368 ret = EMTPRespCodeOK; |
394 } |
369 } |
395 } |
370 } |
396 |
371 |
397 PRINT1( _L( "MM MTP => CRequestChecker::VerifyFormatCode ret = 0x%x" ), ret ); |
372 PRINT1( _L( "MM MTP => CRequestChecker::VerifyFormatCode ret = 0x%x" ), ret ); |
398 |
373 |
399 return ret; |
374 return ret; |
400 } |
375 } |
401 |
376 |
402 // ----------------------------------------------------------------------------- |
377 // ----------------------------------------------------------------------------- |
403 // CRequestChecker::IsSpecialValue |
378 // CRequestChecker::IsSpecialValue |
404 // Check if the parameter is one of the special values |
379 // Check if the parameter is one of the special values |
405 // ----------------------------------------------------------------------------- |
380 // ----------------------------------------------------------------------------- |
406 // |
381 // |
407 TBool CRequestChecker::IsSpecialValue( TUint32 aParameter, |
382 TBool CRequestChecker::IsSpecialValue( TUint32 aParameter, |
408 const TMTPRequestElementInfo& aElementInfo ) const |
383 const TMTPRequestElementInfo& aElementInfo ) const |
409 { |
384 { |
410 TBool result = EFalse; |
385 TBool result = EFalse; |
411 switch ( aElementInfo.iCount ) |
386 switch ( aElementInfo.iCount ) |
412 { |
387 { |
413 case 1: |
388 case 1: |
414 result = ( aParameter == aElementInfo.iValue1 ); |
389 result = ( aParameter == aElementInfo.iValue1 ); |
415 break; |
390 break; |
416 |
391 |
417 case 2: |
392 case 2: |
418 result = ( aParameter == aElementInfo.iValue1 |
393 result = ( aParameter == aElementInfo.iValue1 |
419 || aParameter == aElementInfo.iValue2 ); |
394 || aParameter == aElementInfo.iValue2 ); |
420 break; |
395 break; |
421 |
396 |
422 default: |
397 default: |
423 break; |
398 break; |
424 } |
399 } |
425 |
400 |
426 return result; |
401 return result; |
427 } |
402 } |
428 |
403 |
429 // end of file |
404 // end of file |