diff -r 79d62d1d7957 -r 493788a4a8a4 omadrm/drmengine/dm/src/DRMMessageParser.cpp --- a/omadrm/drmengine/dm/src/DRMMessageParser.cpp Tue Feb 02 00:21:44 2010 +0200 +++ b/omadrm/drmengine/dm/src/DRMMessageParser.cpp Fri Apr 16 15:14:55 2010 +0300 @@ -26,20 +26,20 @@ #include #ifdef RD_MULTIPLE_DRIVE -#include +#include #endif -#include "DrmRights.h" +#include "DRMRights.h" #include "Oma1DcfCreator.h" #include "b64.h" #include "DRMMessageParser.h" -#include "DRMRightsParser.h" +#include "DrmRightsParser.h" #include "DRMRightsClient.h" #include "DrmKeyStorage.h" // EXTERNAL DATA STRUCTURES -// EXTERNAL FUNCTION PROTOTYPES +// EXTERNAL FUNCTION PROTOTYPES // CONSTANTS // MACROS // LOCAL CONSTANTS AND MACROS @@ -54,7 +54,7 @@ _LIT8( KFLSuffix, "@localhost"); LOCAL_C const TUint8 KCDContentIDLength = 25; // 4 + 11 + 10 -LOCAL_C const TUint8 KCDPlainIDLength = 11; +LOCAL_C const TUint8 KCDPlainIDLength = 11; LOCAL_C const TInt KInputBufferSize = 2048; LOCAL_C const TInt KBoundaryMarkLength = 2; @@ -108,7 +108,7 @@ RFs aFs; TFileName aName; }; - + // LOCAL FUNCTION PROTOTYPES LOCAL_C void DoResetAndDestroy( TAny* aPtr ); LOCAL_C void DoResetAndDestroy2( TAny* aPtr ); @@ -126,14 +126,14 @@ void DoResetAndDestroy( TAny* aPtr ) { __ASSERT_DEBUG( aPtr, User::Invariant() ); - + reinterpret_cast< RPointerArray< CDRMRights >* >( aPtr )->ResetAndDestroy(); } void DoResetAndDestroy2( TAny* aPtr ) { __ASSERT_DEBUG( aPtr, User::Invariant() ); - + reinterpret_cast< RPointerArray< CDRMPermission >* >( aPtr )->ResetAndDestroy(); } // ----------------------------------------------------------------------------- @@ -153,28 +153,28 @@ { CDRMAsset* asset( NULL ); CDRMRights* rights( NULL ); - + aRights = NULL; - + rights = CDRMRights::NewL(); CleanupStack::PushL( rights ); - + asset = CDRMAsset::NewL(); CleanupStack::PushL( asset ); - + asset->iUid = aURI.AllocL(); - + if ( aPermission.iParentUID ) { asset->iParentRights = aPermission.iParentUID->AllocL(); } - + rights->SetPermissionL( aPermission ); rights->SetAssetL( *asset ); - + CleanupStack::PopAndDestroy(); // asset CleanupStack::Pop(), // rights - + aRights = rights; } @@ -187,11 +187,11 @@ EXPORT_C CDRMMessageParser* CDRMMessageParser::NewL( void ) { CDRMMessageParser* self = new( ELeave ) CDRMMessageParser(); - + CleanupStack::PushL( self ); self->ConstructL(); CleanupStack::Pop(); - + return self; } @@ -219,23 +219,23 @@ { TInt error = KErrNone; TRAP( error, FinalizeMessageParserL() ); - + Reset(); - + User::Free( const_cast< TUint8* >( iInputBuffer.Ptr() ) ); } // ----------------------------------------------------------------------------- // CDRMMessageParser:: -// +// // ----------------------------------------------------------------------------- // EXPORT_C void CDRMMessageParser::InitializeMessageParserL( RWriteStream& aStream ) { Reset(); - + iDcfCreator = COma1DcfCreator::NewL(); - + iOutputStream = aStream; } @@ -250,8 +250,8 @@ * - a boundary string is located and extracted * - MIME header is read, and based on content-type field the internal * state is set to either EReadingRightsPart or EReadingContentPart. - * - after processing the MIME part, internal state is updated again to - * EReadingHeaderPart if there are several MIME parts in the DRM + * - after processing the MIME part, internal state is updated again to + * EReadingHeaderPart if there are several MIME parts in the DRM * message. * - data is consumed from iInputData in each phase. * - after everything is done, internal state is set to EAllDone. @@ -260,14 +260,14 @@ { User::Leave( KErrNotReady ); } - + if ( iState & EAllDone ) { return; } - + iInputData.Set( aMessageData ); - + while( iInputData.Length() ) { if ( iState & EReadingHeaderPart ) @@ -302,7 +302,7 @@ EXPORT_C void CDRMMessageParser::FinalizeMessageParserL() { TInt error( KErrNone ); - + if ( iState & EEncryptStreamOk ) { if ( iInputBuffer.Length() ) @@ -312,15 +312,15 @@ DeletePermission(); error = KDRMMessageMalformed; } - + ClearBit( EEncryptStreamOk ); iDcfCreator->EncryptFinalizeL(); - + iOutputStream.CommitL(); } Reset(); - + User::LeaveIfError( error ); } @@ -332,9 +332,9 @@ void CDRMMessageParser::ConstructL() { // Make some extra room for crazy b64decode(). - iInputBuffer.Set( reinterpret_cast< TUint8* >( - User::AllocL( KInputBufferSize + 2 ) ), - 0, + iInputBuffer.Set( reinterpret_cast< TUint8* >( + User::AllocL( KInputBufferSize + 2 ) ), + 0, KInputBufferSize ); } @@ -351,30 +351,30 @@ TPtrC8 res( NULL, 0 ); TBool cont( ETrue ); TInt remainder( 0 ); - - // Loop until + + // Loop until // - PrepareContentDataL leaves // - boundary end marker is found // - iInputBuffer is not updated anymore. - for ( PrepareContentDataL(); - iInputBuffer.Length() && - ( remainder != iInputBuffer.Length() ) && + for ( PrepareContentDataL(); + iInputBuffer.Length() && + ( remainder != iInputBuffer.Length() ) && cont; PrepareContentDataL() ) { TInt pos = iInputBuffer.Find( *iBoundary ); - + if ( pos >= 0 ) { - if ( pos < KBoundaryMarkLength + 1 ) + if ( pos < KBoundaryMarkLength + 1 ) { SetBrokenStateL( KDRMMessageMalformed ); } - + res.Set( iInputBuffer.Left( pos - KBoundaryMarkLength ) ); - + StripEndLineL( res ); - + cont = EFalse; } else @@ -383,33 +383,33 @@ // there may be only a part of boundary string in this buffer // and the rest is got from the next input descriptor. remainder = iBoundary->Length() + KBoundaryMarkLength + 1; - + if ( iInputBuffer.Length() <= remainder ) { return; } - - res.Set( iInputBuffer.Left( iInputBuffer.Length() - + + res.Set( iInputBuffer.Left( iInputBuffer.Length() - remainder ) ); } - + if ( iState & EBase64 ) { iUsedFromInput = HandleBase64DataL( res ); } - + else { iUsedFromInput = res.Length(); } - + ProcessContentDataL( res ); - + CompressInputBuffer(); - remainder = iInputBuffer.Length(); + remainder = iInputBuffer.Length(); } - + if ( !cont ) { // Discard all the remaining data. @@ -431,34 +431,34 @@ void CDRMMessageParser::HandleRightsDataL() { TPtrC8 res( NULL, 0 ); - + do { res.Set( GetLineL() ); - + TInt pos = res.Find( *iBoundary ); - + if ( pos >= KBoundaryMarkLength ) { if ( res.Left( KBoundaryMarkLength ) == KBoundaryMark ) { - // Allow empty RO here. If it is not allowed by + // Allow empty RO here. If it is not allowed by // HandleRightsMessagePart(), an error is thrown. TBool last = EFalse; - + // Returns always true. IsBoundary( res, last ); - + if ( last ) { TInt error( KErrNone ); RPointerArray< CDRMRights > rights; - TPtrC8 ptr( iInputBuffer.Ptr(), + TPtrC8 ptr( iInputBuffer.Ptr(), pos - KBoundaryMarkLength ); - + error = ProcessRightsObject(ptr, rights); rights.ResetAndDestroy(); - + if ( !error ) { SetBit( EAllDone ); @@ -470,25 +470,25 @@ } else { - // Save the RO since the CID needs to be either changed + // Save the RO since the CID needs to be either changed // or created. - iRightsData = iInputBuffer.Left( iUsedFromInput - + iRightsData = iInputBuffer.Left( iUsedFromInput - res.Length() ).AllocL(); } - + CompressInputBuffer(); - + ClearBit( EReadingRightsPart ); ClearBit( EGotContentType ); ClearBit( EGotContentEncoding ); SetBit( EGotRightsPart ); SetBit( EReadingHeaderPart ); - + res.Set( NULL, 0 ); #ifndef __DRM_FULL User::Leave(KErrNotSupported); -#endif +#endif } else { @@ -514,31 +514,31 @@ void CDRMMessageParser::FindBoundaryL() { TPtrC8 line( NULL, 0 ); - + FOREVER { line.Set( GetLineL() ); - + if ( line.Length() > KBoundaryMarkLength ) { TInt size = 0; - + if ( line.Left( KBoundaryMarkLength ) == KBoundaryMark ) { size = line.Length() - KBoundaryMarkLength - 1; - + if ( line[ line.Length() - 2 ] == '\r' ) { --size; } - + iBoundary = line.Mid( KBoundaryMarkLength, size ).AllocL(); - + SetBit( EGotBoundary ); SetBit( EReadingHeaderPart ); - + CompressInputBuffer(); - + return; } } @@ -549,7 +549,7 @@ return; } } - + // Something else, not interested. CompressInputBuffer(); } @@ -558,8 +558,8 @@ // ---------------------------------------------------------------------------- // CDRMMessageParser::ReadHeaderL // The boundary is read and the following part is (should be) either a RO part -// or content part. The data is kept in iInputBuffer until the whole header -// part of the MIME header part is received. After plain "\r\n" line is +// or content part. The data is kept in iInputBuffer until the whole header +// part of the MIME header part is received. After plain "\r\n" line is // received and content-type is defined, iState is updated. // ---------------------------------------------------------------------------- // @@ -567,16 +567,16 @@ { TPtrC8 line( NULL, 0 ); TPtrC8 ptr( NULL, 0 ); - + FOREVER { /////////////////////////////////////////////////////////////////// // Process the MIME header line-by-line. Process the lines if they - // contain some information that is found useful. Update the + // contain some information that is found useful. Update the // internal state according to findings. /////////////////////////////////////////////////////////////////// line.Set( GetLineL() ); - + if ( line.Length() ) { if ( line == KEndLine || line == KNewLine ) @@ -586,18 +586,18 @@ /////////////////////////////////////////////// if ( iState & EGotContentType ) { - // Sanity check: Either EReadingRightsPart or + // Sanity check: Either EReadingRightsPart or // EReadingContentPart must defined. __ASSERT_DEBUG( ( iState & EReadingRightsPart ) || - ( iState & EReadingContentPart ), + ( iState & EReadingContentPart ), User::Invariant() ); - + ClearBit( EReadingHeaderPart ); - + CompressInputBuffer(); - + // Check which part was read. - // If content part is being processed, some checkings + // If content part is being processed, some checkings // need to be made. if ( iState & EReadingContentPart ) { @@ -608,53 +608,53 @@ // CD DCF. SetBrokenStateL( KErrCANotSupported ); } - + InitDCFBufferL(); SetBit( EDCFFile ); } else { - // Non-DCF FL content or normal CD content. + // Non-DCF FL content or normal CD content. // Create or modify the CID, save the RO. HandleFlContentL(); - + iDcfCreator->EncryptInitializeL( iOutputStream, *iContentType, iRightsObject ); SetBit( EEncryptStreamOk ); - - // The RO handle iRightsObject is kept in order - // to delete the rights in case of content - // encryption error. In that case, this will + + // The RO handle iRightsObject is kept in order + // to delete the rights in case of content + // encryption error. In that case, this will // generate unnecessary "RO Added / RO Deleted" // notifications, but so what. "More correct" - // way of doing would be modifying - // EncryptInitialize not to + // way of doing would be modifying + // EncryptInitialize not to // save the RO, but then the key would have to // be given to it by other means. Since we are - // not their "friend" class, we cannot access + // not their "friend" class, we cannot access // their members, and making them to ask our // members when doing EncryptInitialize/Finalize // might cause some problems perhaps. } - + delete iContentType; iContentType = NULL; } - + return; } - + // Empty MIME header. SetBrokenStateL( KDRMMessageMalformed ); } - + /////////////////////////////////// // Check the line for content-type. /////////////////////////////////// - if ( line.Length() > KContentType().Length() && + if ( line.Length() > KContentType().Length() && !( line.Left( KContentType().Length() ).CompareF( KContentType ) ) ) { if ( iState & EGotContentType ) @@ -662,11 +662,11 @@ // Content-type given twice. SetBrokenStateL( KDRMMessageMalformed ); } - + ptr.Set( HeaderValueL( line ) ); - + SetBit( EGotContentType ); - + // Which part this is: rights or the actual content? if ( ( ptr.CompareF( KDRMXMLRightsType ) == 0 ) || ( ptr.CompareF( KDRMWBXMLRightsType ) == 0 ) ) @@ -676,7 +676,7 @@ // Rights are given twice. SetBrokenStateL( KDRMMessageMalformed ); } - + SetBit( EReadingRightsPart ); } else @@ -685,9 +685,9 @@ { SetBrokenStateL( KDRMMessageMalformed ); } - + SetBit( EReadingContentPart ); - + // Content-type is saved for future use. iContentType = ptr.AllocL(); } @@ -706,12 +706,12 @@ // Double line. SetBrokenStateL( KDRMMessageMalformed ); } - + ptr.Set( HeaderValueL( line ) ); - + SetBit( EGotContentEncoding ); - // Throw an error if content-transfer-encoding + // Throw an error if content-transfer-encoding // is something we don't support. if ( ptr.CompareF( KEncoding8bit ) && ptr.CompareF( KEncoding7bit) && @@ -721,7 +721,7 @@ { SetBrokenStateL( KErrCANotSupported ); } - + // So it has to be Base64. SetBit( EBase64 ); } @@ -732,20 +732,20 @@ // Check the line for end boundary marker. ////////////////////////////////////////// TBool final( EFalse ); - + if ( IsBoundary( line, final ) ) { SetBrokenStateL( KDRMMessageMalformed ); } - - // Else: some X-field, parameter or something else. + + // Else: some X-field, parameter or something else. // The line is ignored. } } - + CompressInputBuffer(); } - + else { // No line available yet. @@ -763,32 +763,32 @@ { TInt pos = 0; TPtrC8 res( NULL, 0 ); - + if ( iInputBuffer.Length() > iUsedFromInput ) { pos = iInputBuffer.Mid( iUsedFromInput ).Find( KNewLine ); - + if ( pos >= 0 ) { res.Set( iInputBuffer.Mid( iUsedFromInput, pos - iUsedFromInput + 1 ) ); iUsedFromInput = pos + 1; } } - + if ( res.Length() == 0 ) { if ( iInputData.Length() ) { pos = iInputData.Find( KNewLine ); - + if ( pos < 0 ) { - if ( iInputBuffer.MaxSize() - iInputBuffer.Length() < + if ( iInputBuffer.MaxSize() - iInputBuffer.Length() < iInputData.Length() ) { SetBrokenStateL( KDRMMessageMalformed ); } - + iInputBuffer.Append( iInputData ); iInputData.Set( NULL, 0 ); } @@ -799,16 +799,16 @@ { SetBrokenStateL( KDRMMessageMalformed ); } - + iInputBuffer.Append( iInputData.Left( pos + 1 ) ); res.Set( iInputBuffer.Mid( iUsedFromInput ) ); iUsedFromInput = iInputBuffer.Length(); - + iInputData.Set( iInputData.Mid( pos + 1 ) ); } } } - + return res; } @@ -821,23 +821,23 @@ { TInt pos( 0 ); TPtrC8 res( NULL, 0 ); - + pos = aLine.Find( KColon ); - + if ( pos <= 0 ) { SetBrokenStateL( KDRMMessageMalformed ); } - + pos += 1; - - while ( pos < aLine.Length() && + + while ( pos < aLine.Length() && TChar( aLine[ pos ] ).IsSpace() ) { ++pos; } - // Don't overindex. + // Don't overindex. if ( pos == aLine.Length() ) { // Full of whitespaces. @@ -847,27 +847,27 @@ // Drop possible parameters. res.Set( aLine.Mid( pos ) ); pos = res.Find( KSemiColon ); - + if ( pos >= 0 ) { res.Set( res.Left( pos ) ); } - + pos = res.Length(); - + if ( !pos ) { // Just parameters, no actual value. SetBrokenStateL( KDRMMessageMalformed ); } - // This can't underflow, since otherwise there would be only + // This can't underflow, since otherwise there would be only // semicolon & parameters (checked earlier). while( TChar( res[ pos - 1 ] ).IsSpace() ) { --pos; } - + return res.Left( pos ); } @@ -881,11 +881,11 @@ if ( iUsedFromInput ) { const TInt size = iInputBuffer.Length() - iUsedFromInput; - + Mem::Copy( const_cast< TUint8* >( iInputBuffer.Ptr() ), iInputBuffer.Ptr() + iUsedFromInput, size ); - + iInputBuffer.SetLength( size ); iUsedFromInput = 0; } @@ -904,20 +904,20 @@ { SetBrokenStateL( KDRMMessageMalformed ); } - - const TInt size = Min( iInputBuffer.MaxSize() - iInputBuffer.Length(), + + const TInt size = Min( iInputBuffer.MaxSize() - iInputBuffer.Length(), iInputData.Length() ); - + iInputBuffer.Append( iInputData.Left( size ) ); - + iInputData.Set( iInputData.Mid( size ) ); } } - + // ----------------------------------------------------------------------------- // CDRMMessageParser::HandleBase64DataL // Decode base64 encoded data from and to aData descriptor. -// +// // ----------------------------------------------------------------------------- // TInt CDRMMessageParser::HandleBase64DataL( TPtrC8& aData ) @@ -938,19 +938,19 @@ } } } - + if ( consumed != aData.Ptr() ) { - User::LeaveIfError( b64decode( const_cast< TUint8* >( aData.Ptr() ), + User::LeaveIfError( b64decode( const_cast< TUint8* >( aData.Ptr() ), consumed - aData.Ptr() + 1, - const_cast< TUint8* >( aData.Ptr() ), + const_cast< TUint8* >( aData.Ptr() ), &temp1 ) ); - + aData.Set( aData.Ptr(), temp1 ); temp1 = consumed - aData.Ptr() + 1; } - + else { aData.Set( aData.Ptr(), 0 ); @@ -970,17 +970,17 @@ void CDRMMessageParser::StripEndLineL( TPtrC8& aBuf ) { TInt newSize( aBuf.Length() ); - + if ( aBuf.Right( 1 ) == KNewLine ) { --newSize; - - if ( ( aBuf.Length() > 1 ) && + + if ( ( aBuf.Length() > 1 ) && ( aBuf.Right( 2 ) == KEndLine ) ) { --newSize; } - + aBuf.Set( aBuf.Left( newSize ) ); } else @@ -995,28 +995,28 @@ // the end boundary. // ----------------------------------------------------------------------------- // -TBool CDRMMessageParser::IsBoundary( const TDesC8& aLine, TBool& aLast ) const +TBool CDRMMessageParser::IsBoundary( const TDesC8& aLine, TBool& aLast ) const { TBool res = EFalse; - + __ASSERT_DEBUG( iBoundary, User::Invariant() ); - + if ( iState & EGotBoundary ) { if ( aLine.Length() > KBoundaryMarkLength + iBoundary->Length() ) { TPtrC8 tmp( NULL, 0 ); - + if ( ( aLine.Left( KBoundaryMarkLength ) == KBoundaryMark ) && ( aLine.Mid( KBoundaryMarkLength, iBoundary->Length() ). Compare( *iBoundary ) == 0 ) ) { res = ETrue; - - tmp.Set( aLine.Right( aLine.Length() - - KBoundaryMarkLength - + + tmp.Set( aLine.Right( aLine.Length() - + KBoundaryMarkLength - iBoundary->Length() ) ); - + if ( ( tmp.Length() >= KBoundaryMarkLength ) && ( tmp.Left( KBoundaryMarkLength ) == KBoundaryMark ) ) { @@ -1025,7 +1025,7 @@ } } } - + return res; } @@ -1037,23 +1037,23 @@ void CDRMMessageParser::HandleFlContentL() { __ASSERT_DEBUG( !( iState & EDCFFile ), User::Invariant() ); - + if ( iRightsData ) { HBufC8* cid( NULL ); HBufC8* buf( NULL ); - + // RO was found from DRM message. CreateCDCIDL( cid ); CleanupStack::PushL( cid ); - + buf = iRightsData; CleanupStack::PushL( buf ); iRightsData = NULL; - - ProcessRightsDataL( *cid, + + ProcessRightsDataL( *cid, *buf ); - + CleanupStack::PopAndDestroy(); // buf CleanupStack::PopAndDestroy(); // cid } @@ -1069,19 +1069,19 @@ // ----------------------------------------------------------------------------- // CDRMMessageParser::ProcessRightsData -// Process DRM message -style rights object and fetch it to iRightsObject if +// Process DRM message -style rights object and fetch it to iRightsObject if // necessary. // ----------------------------------------------------------------------------- // -void CDRMMessageParser::ProcessRightsDataL( +void CDRMMessageParser::ProcessRightsDataL( const TDesC8& aCID, const TDesC8& aData ) { __ASSERT_DEBUG( !iRightsObject, User::Invariant() ); - + TInt start = aData.Find(KRightsStartTag); TInt end = aData.LocateReverse('>'); - + if ( start >= 0 && end > start ) { TDRMUniqueID localID( 0 ); @@ -1092,39 +1092,39 @@ TBuf8< KDCFKeySize > key; key.SetLength(KDCFKeySize); RPointerArray< CDRMRights > rights; - + TCleanupItem cleanup( DoResetAndDestroy, &rights ); CleanupStack::PushL( cleanup ); - + User::LeaveIfError( client.Connect() ); CleanupClosePushL( client ); - + parser = CDrmRightsParser::NewL(); CleanupStack::PushL( parser ); - + parser->ParseL( ptr, rights ); - + if (rights.Count()==0) - { - User::Leave(KErrCorrupt); - } - + { + User::Leave(KErrCorrupt); + } + client.GetRandomDataL(key); User::LeaveIfError( client.AddRecord( - key, - rights[0]->GetPermission(), - aCID, + key, + rights[0]->GetPermission(), + aCID, localID) ); - + iRightsObject = CDRMRights::NewL(); - + asset = CDRMAsset::NewLC(); asset->iUid = aCID.AllocL(); - + iRightsObject->SetAssetL(*asset); iRightsObject->SetPermissionL(rights[0]->GetPermission()); - + CleanupStack::PopAndDestroy( 4 ); // asset, parser, client, rights } else @@ -1135,7 +1135,7 @@ // ----------------------------------------------------------------------------- // CDRMMessageParser::ProcessContentDataL -// Handle DCF file's CID manipulation in "DCF in DRM message" case. +// Handle DCF file's CID manipulation in "DCF in DRM message" case. // Send the data to EncryptUpdateL if encryption is needed. // ----------------------------------------------------------------------------- // @@ -1165,9 +1165,9 @@ TBool CDRMMessageParser::ValidB64CharL( const TUint8 aChar ) { // Allowed characters are '0'...'9', 'A'...'Z', 'a'...'z', '+', '/', '=' - if ( ( aChar >= 48 && aChar <= 57 ) || + if ( ( aChar >= 48 && aChar <= 57 ) || ( aChar >= 65 && aChar <= 90 ) || - ( aChar >= 97 && aChar <= 122 ) || + ( aChar >= 97 && aChar <= 122 ) || ( aChar == 43 ) || ( aChar == 47 ) || ( aChar == 61 ) ) @@ -1177,7 +1177,7 @@ if ( ( aChar != 0x0D ) && ( aChar != 0x0A ) ) { - SetBrokenStateL( KDRMMessageMalformed ); + SetBrokenStateL( KDRMMessageMalformed ); } return EFalse; @@ -1185,29 +1185,29 @@ // ----------------------------------------------------------------------------- // DRMCommon::ProcessMessage -// +// // ----------------------------------------------------------------------------- EXPORT_C TInt CDRMMessageParser::ProcessMessage( HBufC8*& aDRMMessage) { TInt error( KErrNone ); TRAP( error, DoProcessMessageL( aDRMMessage ) ); - + return error; } - + // ----------------------------------------------------------------------------- // DRMCommon::ProcessRightsObject // Processes a rights objects and saves it in the rights database. // ----------------------------------------------------------------------------- EXPORT_C TInt CDRMMessageParser::ProcessRightsObject( - const TDesC8& aRightsObject, + const TDesC8& aRightsObject, RPointerArray& aRightsDetail) { TInt error( KErrNone ); TRAP( error, DoProcessRightsObjectL( aRightsObject, aRightsDetail ) ); - + return error; } @@ -1215,7 +1215,7 @@ { iState |= aBit; } - + void CDRMMessageParser::ClearBit( TUint32 aBit ) { iState &= ~aBit; @@ -1225,24 +1225,24 @@ { delete iDCFBuffer; iDCFBuffer = NULL; - + delete iDcfCreator; iDcfCreator = NULL; - + delete iRightsData; iRightsData = NULL; - + delete iRightsObject; iRightsObject = NULL; - + delete iBoundary; iBoundary = NULL; - + delete iContentType; iContentType = NULL; - + iInputBuffer.SetLength( 0 ); - + iState = ESearchingBoundary; iDCFHeaderSize[ 0 ] = KMaxTUint32; iDCFHeaderSize[ 1 ] = KMaxTUint32; @@ -1254,63 +1254,63 @@ RFileWriteStream output; RFile file; TInt size( 0 ); - + User::LeaveIfError( fileData.aFs.Connect() ); CleanupClosePushL( fileData.aFs ); TCleanupItem cleanup( DoDeleteFile, &fileData ); CleanupStack::PushL( cleanup ); - + #ifndef RD_MULTIPLE_DRIVE - User::LeaveIfError( output.Temp( fileData.aFs, - KTempPath, - fileData.aName, + User::LeaveIfError( output.Temp( fileData.aFs, + KTempPath, + fileData.aName, EFileWrite ) ); - + #else //RD_MULTIPLE_DRIVE - + TInt driveNumber( -1 ); TChar driveLetter; DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); - fileData.aFs.DriveToChar( driveNumber, driveLetter ); - - TFileName tempPath; - tempPath.Format( KTempPath, (TUint)driveLetter ); + fileData.aFs.DriveToChar( driveNumber, driveLetter ); + + TFileName tempPath; + tempPath.Format( KTempPath, (TUint)driveLetter ); - User::LeaveIfError( output.Temp( fileData.aFs, - tempPath, - fileData.aName, + User::LeaveIfError( output.Temp( fileData.aFs, + tempPath, + fileData.aName, EFileWrite ) ); - + #endif - + CleanupClosePushL( output ); - + InitializeMessageParserL( output ); ProcessMessageDataL( *aDRMMessage ); FinalizeMessageParserL(); - + CleanupStack::PopAndDestroy(); // output - + User::LeaveIfError( file.Open( fileData.aFs, fileData.aName, EFileRead ) ); CleanupClosePushL( file ); - + User::LeaveIfError( file.Size( size ) ); - + if ( size > aDRMMessage->Des().MaxSize() ) { HBufC8* tmp( NULL ); - - delete aDRMMessage; + + delete aDRMMessage; aDRMMessage = NULL; - + tmp = HBufC8::NewLC( size ); TPtr8 data( tmp->Des() ); - + User::LeaveIfError( file.Read( data ) ); CleanupStack::Pop(); // tmp - + aDRMMessage = tmp; } else @@ -1318,22 +1318,22 @@ TPtr8 data( aDRMMessage->Des() ); User::LeaveIfError( file.Read( data ) ); } - + CleanupStack::PopAndDestroy( 3 ); // file, cleanup, fileData.aFs } -void CDRMMessageParser::DoProcessRightsObjectL( - const TDesC8& aRightsObject, +void CDRMMessageParser::DoProcessRightsObjectL( + const TDesC8& aRightsObject, RPointerArray& aRightsDetail ) { CDrmRightsParser* parser = NULL; TInt start; TInt end; TPtrC8 ptr(0, 0); - + start = aRightsObject.Find(KRightsStartTag); end = aRightsObject.LocateReverse('>'); - + TCleanupItem cleanup( DoResetAndDestroy, &aRightsDetail ); CleanupStack::PushL( cleanup ); @@ -1342,16 +1342,16 @@ // xml parser = CDrmRightsParser::NewL(); CleanupStack::PushL(parser); - - ptr.Set(&aRightsObject[start], end - start + 1); - + + ptr.Set(&aRightsObject[start], end - start + 1); + parser->ParseAndStoreL(ptr, aRightsDetail); - + if (aRightsDetail.Count() == 0) { User::Leave( KErrArgument ); } - + CleanupStack::PopAndDestroy(); // parser } else if (start == KErrNotFound ) @@ -1359,23 +1359,23 @@ // wbxml parser = CDrmRightsParser::NewL(CDrmRightsParser::EWbxmlParser); CleanupStack::PushL(parser); - + parser->ParseAndStoreL(aRightsObject, aRightsDetail); if (aRightsDetail.Count() == 0) { User::Leave( KErrArgument ); } - + CleanupStack::PopAndDestroy(); // parser } else { User::Leave( KErrArgument ); } - + CleanupStack::Pop(); // cleanup } - + void CDRMMessageParser::DeletePermission() { if ( iRightsObject ) @@ -1383,28 +1383,28 @@ if ( !( iState & EFLContent ) ) { HBufC8* URI = NULL; - + if ( !( iRightsObject->GetContentURI( URI ) ) ) { __ASSERT_DEBUG( URI, User::Invariant() ); - + RDRMRightsClient client; - + TInt error = client.Connect(); - + if ( !error ) { // Don't care if it fails. client.DeleteDbEntry( *URI, iRightsObject->GetLocalID() ); - + client.Close(); } - + delete URI; URI = NULL; } } - + delete iRightsObject; iRightsObject = NULL; } @@ -1414,7 +1414,7 @@ { SetBit( EBroken ); DeletePermission(); - + User::Leave( aError ); } @@ -1442,7 +1442,7 @@ CleanupStack::PopAndDestroy(); des = KFLPrefix; - + for (TInt i = 0; i < KCDPlainIDLength; i++) { des.AppendNumFixedWidth( id[i], EDecimal, 1 ); @@ -1450,28 +1450,28 @@ des.Append( KFLSuffix ); } - + TInt CDRMMessageParser::RetrieveFlRights() { __ASSERT_DEBUG( !iRightsObject, User::Invariant() ); - + RDRMRightsClient client; TInt error( client.Connect() ); - + if ( !error ) { TRAP( error, EnsureFLRightsExistL( client, &iRightsObject ) ); - + client.Close(); } - + return error; } void CDRMMessageParser::ProcessDCFDataL( TPtrC8& aDCFData ) { TBool doCommit( EFalse ); - + // Loop until all available data is either cached or processed. // What happens is // - modify Content-URI @@ -1485,52 +1485,52 @@ // Modify ContentURI. ////////////////////////////////////////////////////////////////// FillDCFBufferL( aDCFData ); - + if ( iDCFBuffer->Length() > 3 ) { TInt pos = 0; TUint8* data = const_cast< TUint8* > ( iDCFBuffer->Ptr() ); - + if ( data[ 0 ] != 1 ) { SetBrokenStateL( KDRMMessageMalformed ); } - - // Cache the data until - // - version, - // - ContentTypeLen, - // - ContentURILen, - // - ContentType and - // - ContentURI + + // Cache the data until + // - version, + // - ContentTypeLen, + // - ContentURILen, + // - ContentType and + // - ContentURI // have been received. pos = data[ 1 ] + 3; if ( iDCFBuffer->Length() < pos + data[ 2 ] ) { return; } - + // Sanity check. URI has to be more than four ("cid:") octets. if ( data[ 2 ] < 5 ) { SetBrokenStateL( KDRMMessageMalformed ); } - - if ( Mem::CompareF( &data[ pos ], + + if ( Mem::CompareF( &data[ pos ], KCIDStringLength, - KCIDString().Ptr(), + KCIDString().Ptr(), KCIDStringLength ) == 0 ) { // The data length doesn't change, so Mem::Copy() is safe. - Mem::Copy( &data[ pos ], - KFLPrefix().Ptr(), + Mem::Copy( &data[ pos ], + KFLPrefix().Ptr(), KFLKPrefixLength ); - + iOutputStream.WriteL( iDCFBuffer->Left( pos + data[ 2 ] ) ); - + doCommit = ETrue; CompressDCFBuffer( pos + data[ 2 ] ); - + SetBit( EDCFURIModified ); } else @@ -1553,52 +1553,52 @@ if ( !( iState & EDCFHeadersModified ) ) { FillDCFBufferL( aDCFData ); - + // Figure out how much data there is in the header part and/or // in the data part. if ( ( iDCFHeaderSize[ 0 ] == KMaxTUint32 ) && ( iDCFHeaderSize[ 1 ] == KMaxTUint32 ) ) { TUint8 used( 0 ); - + // uintvar has 1...5 octets and we need two uintvars before - // anything can be done. Still, there has to be at least + // anything can be done. Still, there has to be at least // 12 octets of data in total to make the DCF legal. But here // we just check the two uintvars. if ( iDCFBuffer->Length() < 10 ) { // Not enough data yet. - // No need to flush aDCFData at this point, since it + // No need to flush aDCFData at this point, since it // simply cannot contain anything at this point. __ASSERT_DEBUG( !aDCFData.Length(), User::Invariant() ); break; } - + // Read header field length & data length. for ( TUint8 count = 0; count < 2; ++count ) { TInt size( 0 ); - - TWspPrimitiveDecoder decoder( + + TWspPrimitiveDecoder decoder( iDCFBuffer->Mid( used ) ); size = decoder.UintVar( iDCFHeaderSize[ count ] ); - + // Sanity check. if ( size < 1 || iDCFHeaderSize[ count ] >= KMaxTInt ) { SetBrokenStateL( KDRMMessageMalformed ); } - + used += size; } - + CompressDCFBuffer( used ); } else { // We know the original header size now. // Wait until the whole header is read. - if ( static_cast< TUint32 >( iDCFBuffer->Length() ) < + if ( static_cast< TUint32 >( iDCFBuffer->Length() ) < iDCFHeaderSize[ 0 ] ) { if ( !aDCFData.Length() ) @@ -1613,78 +1613,78 @@ TUint length( 0 ); HBufC8* newHeader = NULL; - if ( FindDCFHeader( KRightsIssuer, - offset, + if ( FindDCFHeader( KRightsIssuer, + offset, length ) ) { // The header field exists. TInt pos( 0 ); - TPtr8 trim( const_cast< TUint8* >( + TPtr8 trim( const_cast< TUint8* >( iDCFBuffer->Ptr() ) + offset, - length, + length, length ); iDCFHeaderSize[ 0 ] -= length; // remove old data. - - // No colon, no header value. + + // No colon, no header value. pos = trim.Find( KColon ); if ( pos > 0 ) { - trim.Set( const_cast< TUint8* >( trim.Ptr() ) + pos + 1, + trim.Set( const_cast< TUint8* >( trim.Ptr() ) + pos + 1, trim.Length() - pos - 1, trim.Length() - pos - 1 ); // Skip whitespaces trim.TrimLeft(); trim.TrimRight(); - + if ( trim.Length() ) { // Something to process newHeader = EncryptDCFFieldLC( trim ); - + iDCFHeaderSize[ 0 ] += KRightsIssuer().Length(); iDCFHeaderSize[ 0 ] += newHeader->Length(); iDCFHeaderSize[ 0 ] += 3; // ":" and CRLF } } } - + // Write the uintvars to output. for ( TUint8 loop = 0; loop < 2; ++loop ) { TWspPrimitiveEncoder encoder; HBufC8* var( encoder.UintVarL( iDCFHeaderSize[ loop ] ) ); - + CleanupStack::PushL( var ); - + iOutputStream.WriteL( *var ); - + CleanupStack::PopAndDestroy(); // var } - + // Dump the header data to output stream. iOutputStream.WriteL( iDCFBuffer->Left( offset ) ); - + if ( newHeader ) { iOutputStream.WriteL( KRightsIssuer ); iOutputStream.WriteL( KColon ); iOutputStream.WriteL( *newHeader ); - + CleanupStack::PopAndDestroy(); // newHeader newHeader = NULL; - + iOutputStream.WriteL( KEndLine ); } - iOutputStream.WriteL( - iDCFBuffer->Right( iDCFBuffer->Length() - - offset - + iOutputStream.WriteL( + iDCFBuffer->Right( iDCFBuffer->Length() - + offset - length ) ); - + doCommit = ETrue; - + CompressDCFBuffer( iDCFBuffer->Length() ); SetBit( EDCFHeadersModified ); } @@ -1696,9 +1696,9 @@ __ASSERT_DEBUG( !( iDCFBuffer->Length() ), User::Invariant() ); iOutputStream.WriteL( aDCFData ); - + aDCFData.Set( NULL, 0 ); - + doCommit = ETrue; } } @@ -1718,7 +1718,7 @@ if ( iDCFBuffer->Length() == iDCFBuffer->Des().MaxSize() ) { - HBufC8* ptr = iDCFBuffer->ReAlloc( iDCFBuffer->Length() + + HBufC8* ptr = iDCFBuffer->ReAlloc( iDCFBuffer->Length() + KDefaultInputBufferSize ); if ( !ptr ) @@ -1728,16 +1728,16 @@ iDCFBuffer = ptr; } - - size = Min( iDCFBuffer->Des().MaxSize() - iDCFBuffer->Length(), + + size = Min( iDCFBuffer->Des().MaxSize() - iDCFBuffer->Length(), aData.Length() ); - + iDCFBuffer->Des().Append( aData.Left( size ) ); - + aData.Set( aData.Right( aData.Length() - size ) ); } } - + void CDRMMessageParser::CompressDCFBuffer( const TInt aHowMuch ) { __ASSERT_DEBUG( aHowMuch <= iDCFBuffer->Des().MaxSize(), User::Invariant() ); @@ -1748,7 +1748,7 @@ TUint& aOffset, TUint& aLength ) { - TPtrC8 des( const_cast< TUint8* >( iDCFBuffer->Ptr() ), + TPtrC8 des( const_cast< TUint8* >( iDCFBuffer->Ptr() ), Min( iDCFBuffer->Length(), iDCFHeaderSize[ 0 ] ) ); aOffset = 0; @@ -1770,43 +1770,43 @@ { pos += KEndLineLength; } - - if ( ( pos < aString.Length() ) || + + if ( ( pos < aString.Length() ) || ( des.Left( aString.Length() ).CompareF( aString ) != 0 ) ) { // Skip the line, since this can't be the one we're looking for. - des.Set( des.Right( des.Length() - + des.Set( des.Right( des.Length() - pos ) ); } else { aOffset = des.Ptr() - iDCFBuffer->Ptr(); aLength = pos; - + return ETrue; } } - + // Never reached. return EFalse; } - -void CDRMMessageParser::EnsureFLRightsExistL( - RDRMRightsClient& aClient, + +void CDRMMessageParser::EnsureFLRightsExistL( + RDRMRightsClient& aClient, CDRMRights** aOutput ) { HBufC8* cid( NULL ); CDRMRights* perm( NULL ); RPointerArray< CDRMPermission > rights( 1 ); - + TCleanupItem cleanup( DoResetAndDestroy2, &rights ); CleanupStack::PushL( cleanup ); - + User::LeaveIfError( aClient.ForwardLockURI( cid ) ); CleanupStack::PushL( cid ); - + TRAPD( error, aClient.GetDBEntriesL( *cid, rights ) ); - + if ( !error ) { ConvertPermissionL( perm, *( rights[ 0 ] ), *cid ); @@ -1816,28 +1816,28 @@ { HBufC8* fl( NULL ); RPointerArray< CDRMRights > rightslist( 1 ); - + TCleanupItem cleanup2( DoResetAndDestroy, &rightslist ); CleanupStack::PushL( cleanup2 ); - + fl = HBufC8::NewLC( KFLROSize + cid->Length() ); - + *fl = KROPart1; fl->Des().Append( *cid ); fl->Des().Append( KROPart2 ); - + User::LeaveIfError( ProcessRightsObject( *fl, rightslist ) ); - + CleanupStack::PopAndDestroy(); // fl perm = rightslist[ 0 ]; rightslist.Remove( 0 ); - + CleanupStack::PopAndDestroy(); // cleanup2 - + error = KErrNone; } - + CleanupStack::PopAndDestroy(); // cid if ( !error ) @@ -1852,7 +1852,7 @@ delete perm; perm = NULL; } } - + CleanupStack::PopAndDestroy(); // cleanup } @@ -1861,23 +1861,23 @@ { HBufC8* res = NULL; RDRMRightsClient client; - + User::LeaveIfError( client.Connect() ); CleanupClosePushL( client ); // Make sure FL rights exists. EnsureFLRightsExistL( client, NULL ); - User::LeaveIfError( + User::LeaveIfError( client.EncodeRightsIssuerField( aOldHeader, res ) ); - + CleanupStack::PopAndDestroy(); // client CleanupStack::PushL( res ); return res; } - + // ========================== OTHER EXPORTED FUNCTIONS ========================= // End of File