contentmgmt/referencedrmagent/TestAgent/TestAgentDrmContent.cpp
changeset 15 da2ae96f639b
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <caf/caf.h>
       
    20 #include "TestAgentDrmContent.h"
       
    21 
       
    22 using namespace ContentAccess;
       
    23 
       
    24 CTestAgentDrmContent* CTestAgentDrmContent::NewL(RFile& aFile)
       
    25 	{
       
    26 	CTestAgentDrmContent *self = new (ELeave) CTestAgentDrmContent(aFile);
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL();
       
    29 	CleanupStack::Pop(self);
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CTestAgentDrmContent::CTestAgentDrmContent(RFile& aFile) : iFile(aFile)
       
    34 	{
       
    35 	}
       
    36 
       
    37 CTestAgentDrmContent::~CTestAgentDrmContent()
       
    38 	{	
       
    39 	delete iContentMimeType;
       
    40 	}	
       
    41 
       
    42 void CTestAgentDrmContent::ConstructL()
       
    43 	{
       
    44 	// buffer for reading field sizes from the file
       
    45 	TBuf8 <4> buf;
       
    46 
       
    47 	// Get size of mime type field
       
    48 	User::LeaveIfError(iFile.Read(buf,1));
       
    49 	TUint8 contentTypeLength = buf[0];
       
    50 
       
    51 	// Read mime type field
       
    52 	iContentMimeType = HBufC8::NewL((TInt) contentTypeLength);
       
    53 	TPtr8 mimePtr = iContentMimeType->Des();
       
    54 	User::LeaveIfError(iFile.Read(mimePtr, (TInt) contentTypeLength));
       
    55 	
       
    56 	// Read whether or not file has been imported yet
       
    57 	User::LeaveIfError(iFile.Read(buf,1));
       
    58 	
       
    59 	// Get size of data 
       
    60 	User::LeaveIfError(iFile.Read(buf,4));
       
    61 	iDataSize = buf[0];
       
    62 	iDataSize <<= 8;
       
    63 	iDataSize += buf[1];
       
    64 	iDataSize <<= 8;
       
    65 	iDataSize += buf[2];
       
    66 	iDataSize <<= 8;
       
    67 	iDataSize += buf[3];
       
    68 	
       
    69 	// Calculate offset of data
       
    70 	iDataOffset = 1 + 1 + 4 + contentTypeLength;
       
    71 	
       
    72 	// Go to the start of the DRM file
       
    73 	TInt pos = 0;
       
    74 	Seek(ESeekStart, pos);
       
    75 	}
       
    76 
       
    77 TInt CTestAgentDrmContent::ReadTUintvarL(TDes8& aBuffer, TInt Offset, TInt& aNumBytes) const
       
    78 	{
       
    79 	TUint8 byte;
       
    80 	TInt Value=0;
       
    81 	TBool Continue = ETrue;
       
    82 
       
    83 	for(aNumBytes = 0; Continue ; aNumBytes++)
       
    84 		{
       
    85 		Value <<= 7;
       
    86 		if(Offset + aNumBytes == aBuffer.Length())
       
    87 			User::Leave(KErrOverflow);
       
    88 
       
    89 		byte = aBuffer[Offset + aNumBytes];
       
    90 		if((byte & 0x80) == 0)
       
    91 			{
       
    92 			Continue=EFalse;
       
    93 			}
       
    94 		else 
       
    95 			{
       
    96 			byte &= 0x7F;
       
    97 			}
       
    98 
       
    99 		Value+=byte;
       
   100 		}
       
   101 	return Value;
       
   102 	}
       
   103 
       
   104 
       
   105 TInt CTestAgentDrmContent::Read(TDes8& aDes,TInt aLength)
       
   106 	{
       
   107 	return iFile.Read(aDes, aLength);
       
   108 	}
       
   109 
       
   110 void CTestAgentDrmContent::Read(TDes8& aDes, TInt aLength, TRequestStatus& aStatus)
       
   111 	{
       
   112 	iFile.Read(aDes, aLength, aStatus);
       
   113 	}
       
   114 	
       
   115 void CTestAgentDrmContent::ReadCancel(TRequestStatus& aStatus)
       
   116 {
       
   117 	iFile.ReadCancel(aStatus);
       
   118 }	
       
   119 
       
   120 TInt CTestAgentDrmContent::Seek(TSeek aMode, TInt& aPos)
       
   121 	{
       
   122 	TInt rval;
       
   123 	// Don't allow the user to seek into the OMA header, only around the data itself
       
   124 	TInt Offset;
       
   125 
       
   126 	switch(aMode)
       
   127 		{
       
   128 	case ESeekAddress:
       
   129 		// Unlikely for this case to be used
       
   130 		if(aPos > iDataSize || aPos < 0)
       
   131 			return KErrArgument;
       
   132 
       
   133 		Offset = iDataOffset + aPos;
       
   134 		rval = iFile.Seek(aMode, Offset);
       
   135 		//  Offset is populated with the ROM address, fill in aPos for the caller
       
   136 		aPos=Offset;
       
   137 		break;
       
   138 	
       
   139 	case ESeekStart:
       
   140 		if(aPos > iDataSize)
       
   141 			aPos = iDataSize;
       
   142 		if(aPos < 0)
       
   143 			return KErrArgument;
       
   144 		Offset = iDataOffset + aPos;
       
   145 		rval = iFile.Seek(aMode, Offset);
       
   146 		break;
       
   147 	case ESeekCurrent:
       
   148 		Offset = aPos;
       
   149 		rval = iFile.Seek(aMode, Offset);
       
   150 		// if we have done a seek before the start of the data
       
   151 		// do another seek to get back to the start of the data
       
   152 		if(Offset < iDataOffset)
       
   153 			{
       
   154 			Offset = iDataOffset;
       
   155 			rval = iFile.Seek(ESeekStart, Offset);
       
   156 			aPos = 0;
       
   157 			}
       
   158 		else
       
   159 			{
       
   160 			aPos = Offset - iDataOffset;
       
   161 			}
       
   162 		break;
       
   163 	case ESeekEnd:
       
   164 		// offsets are negative for ESeekEnd
       
   165 		Offset = aPos;
       
   166 		if(Offset < - iDataSize)
       
   167 			Offset = - iDataSize;
       
   168 		rval = iFile.Seek(aMode, Offset);
       
   169 		aPos = Offset - iDataOffset;
       
   170 		break;
       
   171 	default:
       
   172 		return KErrNotSupported;
       
   173 		}
       
   174 	return rval;
       
   175 	}
       
   176 
       
   177 TPtrC8 CTestAgentDrmContent::ContentMimeType()
       
   178 	{
       
   179 	return *iContentMimeType;
       
   180 	}
       
   181 
       
   182 TInt CTestAgentDrmContent::GetAttribute(TInt aAttribute, TInt& aValue)
       
   183 	{
       
   184 	TInt err = KErrNone;
       
   185 	
       
   186 	switch(aAttribute)
       
   187 		{
       
   188 	case EIsProtected:
       
   189 		aValue = ETrue;
       
   190 		break;
       
   191 	case EIsForwardable:
       
   192 		aValue = EFalse;
       
   193 		break;
       
   194 	case EIsModifyable:
       
   195 		aValue = EFalse;
       
   196 		break;
       
   197 	case EIsCopyable:
       
   198 		aValue = EFalse;
       
   199 		break;
       
   200 	case ECanPlay:
       
   201 		aValue = ETrue;
       
   202 		break;
       
   203 	case ECanPrint:
       
   204 		aValue = ETrue;
       
   205 		break;
       
   206 	case ECanExecute:
       
   207 		aValue = ETrue;
       
   208 		break;
       
   209 	case ECanView:
       
   210 		aValue = ETrue;
       
   211 		break;
       
   212 	case EPreviewAvailable:
       
   213 		aValue = EFalse;
       
   214 		break;
       
   215 	case EContentCDataInUse:
       
   216 		aValue = KErrCANotSupported;
       
   217 		break;
       
   218 	case ECanRewind:
       
   219 		aValue = ETrue;
       
   220 		break;
       
   221 	case ECopyPaste:
       
   222 		aValue = ETrue;	
       
   223 		break;
       
   224 	case ECanMove:
       
   225 		aValue = ETrue;
       
   226 		break;
       
   227 	case ECanRename:
       
   228 		aValue = ETrue;
       
   229 		break;
       
   230 	case ECanAutomaticConsume:
       
   231 		aValue = ETrue;
       
   232 		break;
       
   233 	case EContentVersion:
       
   234 	default:
       
   235 		err = KErrCANotSupported;
       
   236 		break;
       
   237 		};
       
   238 	return err;
       
   239 	}
       
   240 	
       
   241 TInt CTestAgentDrmContent::GetStringAttribute(TInt aAttribute, TDes& aValue)
       
   242 	{
       
   243 	TInt err = KErrNone;
       
   244 	switch(aAttribute)
       
   245 		{
       
   246 		// the content object
       
   247 		case EMimeType:
       
   248 		aValue.Copy(*iContentMimeType);
       
   249 		break;
       
   250 	default:
       
   251 		err = KErrCANotSupported;
       
   252 		break;
       
   253 		};
       
   254 	return err;
       
   255 	}
       
   256 
       
   257 void CTestAgentDrmContent::DataSizeL(TInt &aSize)
       
   258 	{
       
   259 	aSize = iDataSize;
       
   260 	}
       
   261 	
       
   262 void CTestAgentDrmContent::Read(TInt aPos, TDes8& aDes, TInt aLength, TRequestStatus& aStatus)
       
   263 	{
       
   264 	TInt offset = aPos + iDataOffset;
       
   265 	iFile.Read(offset, aDes, aLength, aStatus);
       
   266 	}