diff -r e16d72588c28 -r 8a03a285ab14 omadrm/drmengine/roapstorage/src/RoapStorageServer.cpp --- a/omadrm/drmengine/roapstorage/src/RoapStorageServer.cpp Fri Mar 12 15:43:46 2010 +0200 +++ b/omadrm/drmengine/roapstorage/src/RoapStorageServer.cpp Mon Mar 15 12:41:43 2010 +0200 @@ -11,7 +11,7 @@ * * Contributors: * -* Description: +* Description: * */ @@ -21,7 +21,7 @@ #include #ifdef RD_MULTIPLE_DRIVE -#include +#include #endif #include "RoapStorageServer.h" @@ -29,10 +29,10 @@ #include "RoapLog.h" #include "drmroapclientserver.h" #include "drmcommonclientserver.h" -#include "drmkeystorage.h" +#include "DrmKeyStorage.h" // EXTERNAL DATA STRUCTURES -// EXTERNAL FUNCTION PROTOTYPES +// EXTERNAL FUNCTION PROTOTYPES // CONSTANTS // MACROS @@ -77,42 +77,42 @@ // This function starts the actual server under TRAP harness and starts // waiting for connections. This function returns only if there has been // errors during server startup or the server is stopped for some reason. -// +// // Returns: TInt: Symbian OS error code. // ----------------------------------------------------------------------------- -LOCAL_C TInt StartRoapServer( RSemaphore& aClientSem ) +LOCAL_C TInt StartRoapServer( RSemaphore& aClientSem ) { TInt error = KErrNone; CRoapStorageServer* server = NULL; TUint8 count = 0; - do + do { ++count; TRAP( error, ( server = CRoapStorageServer::NewL() ) ); - if ( error ) + if ( error ) { User::After( TTimeIntervalMicroSeconds32(KWaitingTime) ); } - + } while( error && ( count <= KMaxStartTries ) ); - - if( error ) + + if( error ) { return error; } - + // Release the semaphore... aClientSem.Signal(); aClientSem.Close(); - + // Start waiting for connections CActiveScheduler::Start(); - + // Delete CRoapStorageServer delete server; - + return KErrNone; } @@ -121,19 +121,19 @@ // Read a file into a buffer // ----------------------------------------------------------------------------- LOCAL_C void ReadFileL( RFs& aFs, HBufC8*& aContent, const TDesC& aName ) - { - TInt size = 0; - RFile file; - - User::LeaveIfError( file.Open( aFs, aName, EFileRead ) ); - CleanupClosePushL( file ); + { + TInt size = 0; + RFile file; + + User::LeaveIfError( file.Open( aFs, aName, EFileRead ) ); + CleanupClosePushL( file ); User::LeaveIfError( file.Size( size ) ); aContent = HBufC8::NewLC( size ); TPtr8 ptr( aContent->Des() ); User::LeaveIfError( file.Read( ptr, size) ); CleanupStack::Pop(); // aContent - CleanupStack::PopAndDestroy(); // file - } + CleanupStack::PopAndDestroy(); // file + } // ============================ MEMBER FUNCTIONS =============================== @@ -147,14 +147,14 @@ CRoapStorageServer* self = new( ELeave ) CRoapStorageServer(); CleanupStack::PushL( self ); self->ConstructL(); - CleanupStack::Pop( self ); + CleanupStack::Pop( self ); return self; } // ----------------------------------------------------------------------------- // Destructor // ----------------------------------------------------------------------------- -CRoapStorageServer::~CRoapStorageServer() +CRoapStorageServer::~CRoapStorageServer() { iRFs.Close(); delete iRoapStorage; @@ -165,7 +165,7 @@ // From CActive. Complete the request and restart the scheduler. // ----------------------------------------------------------------------------- // -TInt CRoapStorageServer::RunError( TInt aError ) +TInt CRoapStorageServer::RunError( TInt aError ) { // Inform the client. Message().Complete( aError ); @@ -187,8 +187,8 @@ // Check that the versions are compatible. if ( ! User::QueryVersionSupported( TVersion( KServerMajorVersion, KServerMinorVersion, - KServerBuildVersion ), - aVersion ) ) + KServerBuildVersion ), + aVersion ) ) { // Sorry, no can do. User::Leave( KErrNotSupported ); @@ -202,59 +202,59 @@ // might leave. // ----------------------------------------------------------------------------- // -CRoapStorageServer::CRoapStorageServer() : +CRoapStorageServer::CRoapStorageServer() : CServer2( EPriorityStandard ), iRoapStorage( NULL ) { // Nothing } - + // ----------------------------------------------------------------------------- // CRoapStorageServer::ConstructL // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // -void CRoapStorageServer::ConstructL() +void CRoapStorageServer::ConstructL() { TInt err = KErrNone; - + User::RenameThread( KRoapStorageThread ); StartL( Roap::KServerName ); User::LeaveIfError(iRFs.Connect()); - + #ifndef RD_MULTIPLE_DRIVE - - iRoapStorage = CDRMContextDB::NewL( KRIContextFile(), + + iRoapStorage = CDRMContextDB::NewL( KRIContextFile(), KDomainContextFile(), iRFs ); - + #else //RD_MULTIPLE_DRIVE - + TInt driveNumber( -1 ); TChar driveLetter; DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); - iRFs.DriveToChar( driveNumber, driveLetter ); - - TFileName riContextFile; - riContextFile.Format( KRIContextFileName, (TUint)driveLetter ); - + iRFs.DriveToChar( driveNumber, driveLetter ); + + TFileName riContextFile; + riContextFile.Format( KRIContextFileName, (TUint)driveLetter ); + TFileName domainContextFile; - domainContextFile.Format( KDomainContextFileName, (TUint)driveLetter ); - - iRoapStorage = CDRMContextDB::NewL( riContextFile, + domainContextFile.Format( KDomainContextFileName, (TUint)driveLetter ); + + iRoapStorage = CDRMContextDB::NewL( riContextFile, domainContextFile, iRFs ); - + #endif - + TRAP( err, ImportKeysL() ); } - + // ----------------------------------------------------------------------------- // CRoapStorageServer::ContextDB // Return the internal ROAP storage object // ----------------------------------------------------------------------------- -// +// CDRMContextDB* CRoapStorageServer::ContextDB() { return iRoapStorage; @@ -267,10 +267,10 @@ // at a time. The file names are DevicePrivateKey.der, DeviceCert.der and // SigningCertXX.der. // ----------------------------------------------------------------------------- -// +// void CRoapStorageServer::ImportKeysL() { - MDrmKeyStorage* storage = NULL; + MDrmKeyStorage* storage = NULL; HBufC8* privateKey = NULL; HBufC8* cert = NULL; RArray certChain; @@ -280,96 +280,96 @@ TInt i; CDir* dir = NULL; TInt err = KErrNone; - + __UHEAP_MARK; LOG( _L( "CRoapStorageServer::ImportKeysL" ) ); CleanupClosePushL( buffers ); CleanupClosePushL( certChain ); - + #ifndef RD_MULTIPLE_DRIVE - + ReadFileL( iRFs, privateKey, KDeviceKeyFileName ); - + #else //RD_MULTIPLE_DRIVE - + TFileName tempPath; TFileName tempPath2; TInt driveNumber( -1 ); TChar driveLetter; DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); - iRFs.DriveToChar( driveNumber, driveLetter ); - - tempPath.Format( KDeviceKeyFileName, (TUint)driveLetter ); - + iRFs.DriveToChar( driveNumber, driveLetter ); + + tempPath.Format( KDeviceKeyFileName, (TUint)driveLetter ); + ReadFileL( iRFs, privateKey, tempPath ); - + #endif - + CleanupStack::PushL( privateKey ); - + #ifndef RD_MULTIPLE_DRIVE - + ReadFileL( iRFs, cert, KDeviceCertFileName ); - + #else //RD_MULTIPLE_DRIVE - - tempPath2.Format( KDeviceCertFileName, (TUint)driveLetter ); - + + tempPath2.Format( KDeviceCertFileName, (TUint)driveLetter ); + ReadFileL( iRFs, cert, tempPath2 ); - + #endif - + CleanupStack::PushL( cert ); buffers.AppendL( cert ); - + #ifndef RD_MULTIPLE_DRIVE - + iRFs.Delete( KDeviceKeyFileName ); iRFs.Delete( KDeviceCertFileName ); - + #else //RD_MULTIPLE_DRIVE - - iRFs.Delete( tempPath ); + + iRFs.Delete( tempPath ); iRFs.Delete( tempPath2 ); - + #endif - + #ifndef RD_MULTIPLE_DRIVE - + User::LeaveIfError( iRFs.GetDir( KInputFilePattern, KEntryAttNormal, ESortByName, dir ) ); - + #else //RD_MULTIPLE_DRIVE - - tempPath.Format( KInputFilePattern, (TUint)driveLetter ); - + + tempPath.Format( KInputFilePattern, (TUint)driveLetter ); + User::LeaveIfError( iRFs.GetDir( tempPath, KEntryAttNormal, ESortByName, dir ) ); - + #endif - + CleanupStack::PushL( dir ); - + for ( i = 0; i < dir->Count(); i++ ) { - + #ifndef RD_MULTIPLE_DRIVE - + fileName.Copy( KImportDir ); - + #else //RD_MULTIPLE_DRIVE - - tempPath.Format( KImportDir, (TUint)driveLetter ); - + + tempPath.Format( KImportDir, (TUint)driveLetter ); + fileName.Copy( tempPath ); - + #endif - + fileName.Append( (*dir)[i].iName ); ReadFileL( iRFs, cert, fileName ); CleanupStack::PushL( cert ); buffers.AppendL( cert ); - + iRFs.Delete( fileName ); } for ( i = 0; i < buffers.Count(); i++ ) @@ -394,21 +394,21 @@ // ----------------------------------------------------------------------------- // -TInt StartupRoapStorage( TAny* ) - { +TInt StartupRoapStorage( TAny* ) + { TInt error = KErrNone; CTrapCleanup* trap = CTrapCleanup::New(); __ASSERT_ALWAYS( trap, User::Invariant() ); - + CActiveScheduler* scheduler = new CActiveScheduler(); __ASSERT_ALWAYS( scheduler, User::Invariant() ); - + CActiveScheduler::Install( scheduler ); RSemaphore clientSem; __ASSERT_ALWAYS( clientSem.OpenGlobal( KDRMEngCommonSemaphore ) == 0, User::Invariant() ); - + error = StartRoapServer( clientSem ); - + if ( error ) { // Server creation failed. Release the semaphore. // In case of successful startup, CRoapStorageServer @@ -416,15 +416,15 @@ clientSem.Signal(); clientSem.Close(); } - - delete scheduler; + + delete scheduler; scheduler = NULL; - + delete trap; trap = NULL; - + // __ASSERT_ALWAYS( !error, User::Invariant() ); - + return KErrNone; }