omadrm/drmengine/roap/src/DeviceHello.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 "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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <hash.h>
       
    23 #include "Base64.h"
       
    24 #include "DeviceHello.h"
       
    25 
       
    26 using namespace Roap;
       
    27 
       
    28 // CONSTANTS
       
    29 _LIT8(KReqHeader, "<roap:deviceHello xmlns:roap=\"urn:oma:bac:dldrm:roap-1.0\"");
       
    30 _LIT8(KReqVersion, "><version>");
       
    31 _LIT8(KReqNonceTrigger, " triggerNonce=\"");
       
    32 _LIT8(KReqVersion2, "\"><version>");
       
    33 _LIT8(KReqVersionEnd, "</version>");
       
    34 _LIT8(KReqDeviceIdStart, "<deviceID>");
       
    35 _LIT8(KReqKeyIndentifierStart,"<keyIdentifier xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    36  algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>");
       
    37 _LIT8(KReqKeyIndentifierEnd, "</hash></keyIdentifier>");
       
    38 _LIT8(KReqDeviceIdEnd,"</deviceID>");
       
    39 _LIT8(KReqSupportedAlgo, "<supportedAlgorithm>");
       
    40 _LIT8(KReqSupportedAlgoEnd, "</supportedAlgorithm>");
       
    41 _LIT8(KReqExtensions, "<extensions>");
       
    42 _LIT8(KReqExtensionsEnd, "</extensions>");
       
    43 _LIT8(KReqCertificateCaching, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\
       
    44  xsi:type=\"roap:CertificateCaching\"></extension>");
       
    45 _LIT8(KReqEnd, "</roap:deviceHello>");
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CDeviceHello::CDeviceHello
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CDeviceHello::CDeviceHello():
       
    56     iTriggerNonce(NULL)
       
    57     {
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CDeviceHello::ConstructL
       
    62 // Symbian 2nd phase constructor can leave.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 void CDeviceHello::ConstructL()
       
    66     {
       
    67     iVersion.SetLength(0);
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CDeviceHello::NewL
       
    72 // Two-phased constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CDeviceHello* CDeviceHello::NewL()
       
    76     {
       
    77     CDeviceHello* self = new( ELeave ) CDeviceHello;
       
    78     
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     CleanupStack::Pop();
       
    82 
       
    83     return self;
       
    84     }
       
    85 
       
    86     
       
    87 // Destructor
       
    88 CDeviceHello::~CDeviceHello()
       
    89     {
       
    90     iAlgorithms.Close();
       
    91     delete iTriggerNonce;
       
    92     iTriggerNonce = NULL;
       
    93     iDeviceIdArray.Close();
       
    94     }
       
    95     
       
    96 // -----------------------------------------------------------------------------
       
    97 // CDeviceHello::?member_function
       
    98 // ?implementation_description
       
    99 // (other items were commented in a header).
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 HBufC8* CDeviceHello::MessageAsXmlL(void)
       
   103     {
       
   104     HBufC8* r = NULL;
       
   105     CBufFlat* b = NULL;
       
   106     TInt i = 0;
       
   107 
       
   108     b = CBufFlat::NewL(128);
       
   109     CleanupStack::PushL(b);
       
   110     BufAppendL(b, KReqHeader);   
       
   111     if (iTriggerNonce)
       
   112         {
       
   113         BufAppendL(b, KReqNonceTrigger);
       
   114         BufAppendL(b, *iTriggerNonce);
       
   115         BufAppendL(b, KReqVersion2);
       
   116         BufAppendL(b, iVersion);
       
   117         GetDeviceIdsAsXmlL( b );
       
   118         }
       
   119     else
       
   120         {
       
   121         BufAppendL(b, KReqVersion);
       
   122         BufAppendL(b, iVersion);
       
   123         GetDeviceIdsAsXmlL( b ); 
       
   124         }
       
   125 
       
   126     for (i = 0; i < iAlgorithms.Count(); i++)
       
   127         {
       
   128         TPtrC8 p(0, 0);
       
   129         BufAppendL(b, KReqSupportedAlgo);
       
   130         p.Set(iAlgorithms[i]);
       
   131         BufAppendL(b, p);
       
   132         BufAppendL(b, KReqSupportedAlgoEnd);
       
   133         }
       
   134         
       
   135     BufAppendL(b, KReqExtensions);
       
   136     BufAppendL(b, KReqCertificateCaching);        
       
   137     BufAppendL(b, KReqExtensionsEnd);        
       
   138 
       
   139     
       
   140     BufAppendL(b, KReqEnd);
       
   141         
       
   142     r = b->Ptr(0).AllocL();
       
   143     CleanupStack::PopAndDestroy(); // b
       
   144     return r;
       
   145     }
       
   146     
       
   147 // -----------------------------------------------------------------------------
       
   148 // CDeviceHello::?member_function
       
   149 // ?implementation_description
       
   150 // (other items were commented in a header).
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CDeviceHello::GetDeviceIdsAsXmlL(CBufFlat* aBuffer)
       
   154     {
       
   155     BufAppendL(aBuffer, KReqVersionEnd);
       
   156     
       
   157     for (TInt i = 0; i < iDeviceIdArray.Count(); i++)
       
   158         {
       
   159         HBufC8* buffer( Base64EncodeL(iDeviceIdArray[i]) );
       
   160         CleanupStack::PushL( buffer );
       
   161         BufAppendL(aBuffer, KReqDeviceIdStart);
       
   162 
       
   163         BufAppendL(aBuffer, KReqKeyIndentifierStart);
       
   164         BufAppendL(aBuffer, *buffer);
       
   165         BufAppendL(aBuffer, KReqKeyIndentifierEnd);
       
   166         BufAppendL(aBuffer, KReqDeviceIdEnd);
       
   167         CleanupStack::PopAndDestroy( buffer );
       
   168         }
       
   169     }
       
   170 
       
   171 //  End of File