diff -r 000000000000 -r 95b198f216e5 omadrm/drmengine/roap/src/DeviceHello.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/omadrm/drmengine/roap/src/DeviceHello.cpp Thu Dec 17 08:52:27 2009 +0200 @@ -0,0 +1,171 @@ +/* +* Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: ?Description +* +*/ + + + +// INCLUDE FILES +#include +#include +#include "Base64.h" +#include "DeviceHello.h" + +using namespace Roap; + +// CONSTANTS +_LIT8(KReqHeader, ""); +_LIT8(KReqNonceTrigger, " triggerNonce=\""); +_LIT8(KReqVersion2, "\">"); +_LIT8(KReqVersionEnd, ""); +_LIT8(KReqDeviceIdStart, ""); +_LIT8(KReqKeyIndentifierStart,""); +_LIT8(KReqKeyIndentifierEnd, ""); +_LIT8(KReqDeviceIdEnd,""); +_LIT8(KReqSupportedAlgo, ""); +_LIT8(KReqSupportedAlgoEnd, ""); +_LIT8(KReqExtensions, ""); +_LIT8(KReqExtensionsEnd, ""); +_LIT8(KReqCertificateCaching, ""); +_LIT8(KReqEnd, ""); + +// ============================ MEMBER FUNCTIONS =============================== + +// ----------------------------------------------------------------------------- +// CDeviceHello::CDeviceHello +// C++ default constructor can NOT contain any code, that +// might leave. +// ----------------------------------------------------------------------------- +// +CDeviceHello::CDeviceHello(): + iTriggerNonce(NULL) + { + } + +// ----------------------------------------------------------------------------- +// CDeviceHello::ConstructL +// Symbian 2nd phase constructor can leave. +// ----------------------------------------------------------------------------- +// +void CDeviceHello::ConstructL() + { + iVersion.SetLength(0); + } + +// ----------------------------------------------------------------------------- +// CDeviceHello::NewL +// Two-phased constructor. +// ----------------------------------------------------------------------------- +// +CDeviceHello* CDeviceHello::NewL() + { + CDeviceHello* self = new( ELeave ) CDeviceHello; + + CleanupStack::PushL( self ); + self->ConstructL(); + CleanupStack::Pop(); + + return self; + } + + +// Destructor +CDeviceHello::~CDeviceHello() + { + iAlgorithms.Close(); + delete iTriggerNonce; + iTriggerNonce = NULL; + iDeviceIdArray.Close(); + } + +// ----------------------------------------------------------------------------- +// CDeviceHello::?member_function +// ?implementation_description +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +// +HBufC8* CDeviceHello::MessageAsXmlL(void) + { + HBufC8* r = NULL; + CBufFlat* b = NULL; + TInt i = 0; + + b = CBufFlat::NewL(128); + CleanupStack::PushL(b); + BufAppendL(b, KReqHeader); + if (iTriggerNonce) + { + BufAppendL(b, KReqNonceTrigger); + BufAppendL(b, *iTriggerNonce); + BufAppendL(b, KReqVersion2); + BufAppendL(b, iVersion); + GetDeviceIdsAsXmlL( b ); + } + else + { + BufAppendL(b, KReqVersion); + BufAppendL(b, iVersion); + GetDeviceIdsAsXmlL( b ); + } + + for (i = 0; i < iAlgorithms.Count(); i++) + { + TPtrC8 p(0, 0); + BufAppendL(b, KReqSupportedAlgo); + p.Set(iAlgorithms[i]); + BufAppendL(b, p); + BufAppendL(b, KReqSupportedAlgoEnd); + } + + BufAppendL(b, KReqExtensions); + BufAppendL(b, KReqCertificateCaching); + BufAppendL(b, KReqExtensionsEnd); + + + BufAppendL(b, KReqEnd); + + r = b->Ptr(0).AllocL(); + CleanupStack::PopAndDestroy(); // b + return r; + } + +// ----------------------------------------------------------------------------- +// CDeviceHello::?member_function +// ?implementation_description +// (other items were commented in a header). +// ----------------------------------------------------------------------------- +// +void CDeviceHello::GetDeviceIdsAsXmlL(CBufFlat* aBuffer) + { + BufAppendL(aBuffer, KReqVersionEnd); + + for (TInt i = 0; i < iDeviceIdArray.Count(); i++) + { + HBufC8* buffer( Base64EncodeL(iDeviceIdArray[i]) ); + CleanupStack::PushL( buffer ); + BufAppendL(aBuffer, KReqDeviceIdStart); + + BufAppendL(aBuffer, KReqKeyIndentifierStart); + BufAppendL(aBuffer, *buffer); + BufAppendL(aBuffer, KReqKeyIndentifierEnd); + BufAppendL(aBuffer, KReqDeviceIdEnd); + CleanupStack::PopAndDestroy( buffer ); + } + } + +// End of File