mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/crequestchecker.cpp
branchRCL_3
changeset 17 780c925249c1
parent 14 05b0d2323768
child 53 e42293e811d8
equal deleted inserted replaced
15:d240f0a77280 17:780c925249c1
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <mtp/cmtpobjectmetadata.h>
       
    20 #include <mtp/mmtpconnection.h>
    19 #include <mtp/mmtpconnection.h>
    21 #include <mtp/mmtpdataproviderframework.h>
    20 #include <mtp/mmtpdataproviderframework.h>
    22 #include <mtp/mmtpobjectmgr.h>
    21 #include <mtp/mmtpobjectmgr.h>
    23 #include <mtp/mmtpstoragemgr.h>
    22 #include <mtp/mmtpstoragemgr.h>
    24 
    23 
   209 // 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),
   210 // this usually only applies to the OpenSession request
   209 // this usually only applies to the OpenSession request
   211 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   212 //
   211 //
   213 TMTPResponseCode CRequestChecker::VerifySessionId( TUint32 aSessionId,
   212 TMTPResponseCode CRequestChecker::VerifySessionId( TUint32 aSessionId,
   214         const TMTPRequestElementInfo& /*aElementInfo*/ ) const
   213     const TMTPRequestElementInfo& /*aElementInfo*/ ) const
   215     {
   214     {
   216     TMTPResponseCode ret = EMTPRespCodeOK;
   215     TMTPResponseCode ret = EMTPRespCodeOK;
   217 
   216 
   218     if ( aSessionId != 0 )
   217     if ( aSessionId != 0 )
   219         {
   218         {
   235 // 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,
   236 // read/write, file/dir
   235 // read/write, file/dir
   237 // -----------------------------------------------------------------------------
   236 // -----------------------------------------------------------------------------
   238 //
   237 //
   239 TMTPResponseCode CRequestChecker::VerifyObjectHandleL( TUint32 aHandle,
   238 TMTPResponseCode CRequestChecker::VerifyObjectHandleL( TUint32 aHandle,
   240         const TMTPRequestElementInfo& aElementInfo )
   239     const TMTPRequestElementInfo& aElementInfo )
   241     {
   240     {
   242     PRINT1( _L("MM MTP => CRequestChecker::VerifyObjectHandleL aHandle = 0x%x"), aHandle );
   241     PRINT1( _L("MM MTP => CRequestChecker::VerifyObjectHandleL aHandle = 0x%x"), aHandle );
   243     TMTPResponseCode ret = EMTPRespCodeOK;
   242     TMTPResponseCode ret = EMTPRespCodeOK;
   244 
   243 
   245     CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC() );
   244     CMTPObjectMetaData* object( CMTPObjectMetaData::NewLC() );
   253         {
   252         {
   254         const TDesC& suid( object->DesC( CMTPObjectMetaData::ESuid ) );
   253         const TDesC& suid( object->DesC( CMTPObjectMetaData::ESuid ) );
   255         TEntry entry;
   254         TEntry entry;
   256         TInt err = iFramework.Fs().Entry( suid, entry );
   255         TInt err = iFramework.Fs().Entry( suid, entry );
   257 
   256 
   258         if ( object->Uint( CMTPObjectMetaData::EFormatCode ) == EMTPFormatCodeAssociation )
   257         if ( err == KErrNotFound )
   259 //            && ( object->Uint( CMTPObjectMetaData::EFormatSubCode ) == EMTPAssociationTypeGenericFolder ) )
   258             {
   260             {
   259             iFramework.ObjectMgr().RemoveObjectL( suid );
   261             // Special association type .. not always present on the filesystem.
   260             // TODO: workaround for abstractalbumart
   262             return ret;
   261             // ret = EMTPRespCodeInvalidObjectHandle;
   263             }
   262             }
   264         else
   263         else if ( err != KErrNone )
   265             {
   264             ret = EMTPRespCodeGeneralError;
   266             User::LeaveIfError( err );
   265         else if ( object->Uint( CMTPObjectMetaData::EFormatCode ) != EMTPFormatCodeAssociation )
   267 
   266             {
   268             if ( iFramework.ObjectMgr().ObjectOwnerId( aHandle ) != iFramework.DataProviderId() )
   267             if ( iFramework.ObjectMgr().ObjectOwnerId( aHandle ) != iFramework.DataProviderId() )
   269                 {
       
   270                 PRINT( _L(" ewrwe ret = EMTPRespCodeInvalidObjectHandle;"));
       
   271                 ret = EMTPRespCodeInvalidObjectHandle;
   268                 ret = EMTPRespCodeInvalidObjectHandle;
   272                 }
   269 
   273             }
   270             if ( ( aElementInfo.iElementAttr & EMTPElementAttrWrite ) && entry.IsReadOnly() )
   274 
       
   275         if ( aElementInfo.iElementAttr & EMTPElementAttrWrite )
       
   276             {
       
   277             if ( entry.IsReadOnly() )
       
   278                 {
       
   279                 ret = EMTPRespCodeObjectWriteProtected;
   271                 ret = EMTPRespCodeObjectWriteProtected;
   280                 }
   272 
   281             }
   273             if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrFile ) && entry.IsDir() )
   282 
       
   283         //((EMTPRespCodeOK == ret) && (aElementInfo.iElementAttr & EMTPElementAttrFileOrDir)) is
       
   284         // covered implicitly here, EMTPRespCodeOK will be returned. It is a valid case for an object to be either a folder or file
       
   285         // for certain operation's request parameter, for instance the first parameter of copyObject or
       
   286         // moveObject can be either a file or a directory.
       
   287 
       
   288         // Other cases.
       
   289         if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrFile ) )
       
   290             {
       
   291             if ( entry.IsDir() )
       
   292                 {
       
   293                 ret = EMTPRespCodeInvalidObjectHandle;
   274                 ret = EMTPRespCodeInvalidObjectHandle;
   294                 }
   275 
   295             }
   276             if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrDir ) && !entry.IsDir() )
   296 
       
   297         if ( ( EMTPRespCodeOK == ret ) && ( aElementInfo.iElementAttr & EMTPElementAttrDir ) )
       
   298             {
       
   299             if (!entry.IsDir())
       
   300                 {
       
   301                 ret = EMTPRespCodeInvalidParentObject;
   277                 ret = EMTPRespCodeInvalidParentObject;
   302                 }
       
   303             }
   278             }
   304         }
   279         }
   305     else
   280     else
   306         {
       
   307         PRINT( _L( "MM MTP <> CRequestChecker::VerifyObjectHandleL, Object does not exist." ) );
       
   308         ret = EMTPRespCodeInvalidObjectHandle;
   281         ret = EMTPRespCodeInvalidObjectHandle;
   309         }
   282 
   310     PRINT1( _L( "MM MTP <= CRequestChecker::VerifyObjectHandleL ret = 0x%x" ), ret );
   283     PRINT1( _L( "MM MTP <= CRequestChecker::VerifyObjectHandleL ret = 0x%x" ), ret );
   311 
   284 
   312     return ret;
   285     return ret;
   313     }
   286     }
   314 
   287 
   316 // CRequestChecker::VerifyStorageIdL
   289 // CRequestChecker::VerifyStorageIdL
   317 // Check the storage id parameter in the request, read/write attributes
   290 // Check the storage id parameter in the request, read/write attributes
   318 // -----------------------------------------------------------------------------
   291 // -----------------------------------------------------------------------------
   319 //
   292 //
   320 TMTPResponseCode CRequestChecker::VerifyStorageIdL( TUint32 aStorageId,
   293 TMTPResponseCode CRequestChecker::VerifyStorageIdL( TUint32 aStorageId,
   321         const TMTPRequestElementInfo& aElementInfo ) const
   294     const TMTPRequestElementInfo& aElementInfo ) const
   322     {
   295     {
   323     MMTPStorageMgr& mgr( iFramework.StorageMgr() );
   296     MMTPStorageMgr& mgr( iFramework.StorageMgr() );
   324     TMTPResponseCode ret( EMTPRespCodeOK );
   297     TMTPResponseCode ret( EMTPRespCodeOK );
   325     if ( !mgr.ValidStorageId( aStorageId ) )
   298     if ( !mgr.ValidStorageId( aStorageId ) )
   326         {
   299         {
   367 // CRequestChecker::VerifyFormatCode
   340 // CRequestChecker::VerifyFormatCode
   368 // Check the format code parameter in the request
   341 // Check the format code parameter in the request
   369 // -----------------------------------------------------------------------------
   342 // -----------------------------------------------------------------------------
   370 //
   343 //
   371 TMTPResponseCode CRequestChecker::VerifyFormatCode( TUint32 aFormatCode,
   344 TMTPResponseCode CRequestChecker::VerifyFormatCode( TUint32 aFormatCode,
   372         const TMTPRequestElementInfo& aElementInfo ) const
   345     const TMTPRequestElementInfo& aElementInfo ) const
   373     {
   346     {
   374     PRINT1( _L( "MM MTP => CRequestChecker::VerifyFormatCode aFormatCode = 0x%x" ), aFormatCode );
   347     PRINT1( _L( "MM MTP => CRequestChecker::VerifyFormatCode aFormatCode = 0x%x" ), aFormatCode );
   375     TMTPResponseCode ret = EMTPRespCodeInvalidObjectFormatCode;
   348     TMTPResponseCode ret = EMTPRespCodeInvalidObjectFormatCode;
   376 
   349 
   377     if ( aElementInfo.iElementAttr == EMTPElementAttrFormatEnums )
   350     if ( aElementInfo.iElementAttr == EMTPElementAttrFormatEnums )
   405 // CRequestChecker::IsSpecialValue
   378 // CRequestChecker::IsSpecialValue
   406 // Check if the parameter is one of the special values
   379 // Check if the parameter is one of the special values
   407 // -----------------------------------------------------------------------------
   380 // -----------------------------------------------------------------------------
   408 //
   381 //
   409 TBool CRequestChecker::IsSpecialValue( TUint32 aParameter,
   382 TBool CRequestChecker::IsSpecialValue( TUint32 aParameter,
   410         const TMTPRequestElementInfo& aElementInfo ) const
   383     const TMTPRequestElementInfo& aElementInfo ) const
   411     {
   384     {
   412     TBool result = EFalse;
   385     TBool result = EFalse;
   413     switch ( aElementInfo.iCount )
   386     switch ( aElementInfo.iCount )
   414         {
   387         {
   415         case 1:
   388         case 1: