1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/Cafutils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,87 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +
1.23 +#include <e32base.h>
1.24 +#include <s32strm.h>
1.25 +#include "cafutils.h"
1.26 +
1.27 +using namespace ContentAccess;
1.28 +
1.29 +HBufC* TCafUtils::ReadDescriptor16L(RReadStream& aStream)
1.30 + {
1.31 + // Read the unicode data from the stream
1.32 + TInt dataLength = aStream.ReadInt32L();
1.33 + HBufC* iData = HBufC::NewL(dataLength);
1.34 + CleanupStack::PushL(iData);
1.35 + if(dataLength > 0)
1.36 + {
1.37 + TPtr dataPtr = iData->Des();
1.38 + aStream.ReadL(dataPtr, dataLength);
1.39 + }
1.40 + CleanupStack::Pop(iData);
1.41 + return iData;
1.42 + }
1.43 +
1.44 +void TCafUtils::WriteDescriptor16L(RWriteStream& aStream, const TDesC& aDescriptor)
1.45 + {
1.46 + // Write unicode data to the stream
1.47 + aStream.WriteInt32L(aDescriptor.Length());
1.48 + aStream.WriteL(aDescriptor);
1.49 + }
1.50 +
1.51 +HBufC8* TCafUtils::ReadDescriptor8L(RReadStream& aStream)
1.52 + {
1.53 + // Read the 8 bit data from a stream
1.54 + TInt dataLength = aStream.ReadInt32L();
1.55 + HBufC8* iData = HBufC8::NewL(dataLength);
1.56 + CleanupStack::PushL(iData);
1.57 + if(dataLength > 0)
1.58 + {
1.59 + TPtr8 dataPtr = iData->Des();
1.60 + aStream.ReadL(dataPtr, dataLength);
1.61 + }
1.62 + CleanupStack::Pop(iData);
1.63 + return iData;
1.64 + }
1.65 +
1.66 +void TCafUtils::ReadDescriptor8L(RReadStream& aStream, TDes8& aBuffer)
1.67 + {
1.68 + aBuffer.SetLength(0);
1.69 +
1.70 + // Read the 8 bit data from a stream
1.71 + TInt dataLength = aStream.ReadInt32L();
1.72 + if(dataLength > aBuffer.MaxLength())
1.73 + {
1.74 + User::Leave(KErrOverflow);
1.75 + }
1.76 + if(dataLength > 0)
1.77 + {
1.78 + aStream.ReadL(aBuffer, dataLength);
1.79 + }
1.80 + }
1.81 +
1.82 +void TCafUtils::WriteDescriptor8L(RWriteStream& aStream, const TDesC8& aDescriptor)
1.83 + {
1.84 + // Write 8 bit data to a stream
1.85 + aStream.WriteInt32L(aDescriptor.Length());
1.86 + aStream.WriteL(aDescriptor);
1.87 + }
1.88 +
1.89 +// DLL entry point - only for EKA1
1.90 +