omadrm/drmengine/roap/src/RightsRespParser.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 "Base64.h"
       
    23 #include "RoapParser.h"
       
    24 #include "RightsResp.h"
       
    25 #include "RightsRespParser.h"
       
    26 
       
    27 using namespace Roap;
       
    28 
       
    29 // LOCAL CONSTANTS AND MACROS
       
    30 _LIT8(KStatus, "status");
       
    31 _LIT8(KSessionId, "sessionId");
       
    32 _LIT8(KErrorUrl, "errorRedirectURL");
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // TRightsRespParser::TRightsRespParser
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 TRightsRespParser::TRightsRespParser(
       
    43     CRightsResp* aResponse)
       
    44     {
       
    45     iResponse = aResponse;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // TRightsRespParser::?member_function
       
    50 // ?implementation_description
       
    51 // (other items were commented in a header).
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void TRightsRespParser::OnStartElementL(
       
    55     CRoapParser& aParser,
       
    56     TInt aState,
       
    57     const RTagInfo& /*aElement*/,
       
    58     const RAttributeArray& aAttributes)
       
    59     {
       
    60     HBufC8* buffer = NULL;
       
    61 
       
    62     switch (aState)
       
    63         {
       
    64         case ERoResponseState:
       
    65             buffer = aParser.GetAttributeValueL(aAttributes, KStatus);
       
    66             if (buffer != NULL)
       
    67                 {
       
    68                 iResponse->iStatus = aParser.ConvertRoapStatus(*buffer);
       
    69                 delete buffer;
       
    70                 }
       
    71             else
       
    72                 {
       
    73                 iResponse->iStatus = EUnknownStatus;
       
    74                 }
       
    75             iResponse->iSession =
       
    76                 aParser.GetAttributeValueL(aAttributes, KSessionId);
       
    77                 
       
    78             iResponse->iErrorUrl = aParser.GetAttributeValueL(aAttributes, KErrorUrl);
       
    79             break;
       
    80         }
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // TRightsRespParser::?member_function
       
    85 // ?implementation_description
       
    86 // (other items were commented in a header).
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void TRightsRespParser::OnEndElementL(
       
    90     CRoapParser& aParser,
       
    91     TInt aState,
       
    92     const RTagInfo& /*aElement*/)
       
    93     {
       
    94     HBufC8* buffer = NULL;
       
    95     
       
    96     if ( !aParser.iContent )
       
    97         {
       
    98         return;
       
    99         }
       
   100 
       
   101     switch (aState)
       
   102         {
       
   103         case ECertificateState:
       
   104             buffer = Base64DecodeL(*aParser.iContent);
       
   105             CleanupStack::PushL(buffer);
       
   106             iResponse->iCertificateChain.AppendL(buffer);
       
   107             CleanupStack::Pop(); // buffer
       
   108             break;
       
   109         case EOcspResponseState:
       
   110             buffer = Base64DecodeL(*aParser.iContent);
       
   111             CleanupStack::PushL(buffer);
       
   112             iResponse->iOcspResponse.AppendL(buffer);
       
   113             CleanupStack::Pop(); // buffer
       
   114             break;
       
   115         case ERiIdRoResponseState:
       
   116             buffer = Base64DecodeL(*aParser.iContent);
       
   117             if ( buffer->Length() > SHA1_HASH )
       
   118                 {
       
   119                 delete buffer;
       
   120                 buffer = NULL;
       
   121                 User::Leave( KErrCorrupt );
       
   122                 }
       
   123             iResponse->iRiId.Copy(*buffer);
       
   124             delete buffer;
       
   125             break;
       
   126         case EDeviceIdState:
       
   127             buffer = Base64DecodeL(*aParser.iContent);
       
   128             if ( buffer->Length() > SHA1_HASH )
       
   129                 {
       
   130                 delete buffer;
       
   131                 buffer = NULL;
       
   132                 User::Leave( KErrCorrupt );
       
   133                 }
       
   134             iResponse->iDeviceId.Copy(*buffer);
       
   135             delete buffer;
       
   136             break;
       
   137         case ENonceState:
       
   138             iResponse->iNonce = Base64DecodeL(*aParser.iContent);
       
   139             break;
       
   140         case ESignatureRoResponseState:
       
   141             iResponse->iSignature = Base64DecodeL(*aParser.iContent);
       
   142             break;
       
   143         case EEncKeyState:
       
   144             iResponse->iRoEncryptionKey = Base64DecodeL(*aParser.iContent);
       
   145             break;
       
   146         case ETransactionIdContentIdState:
       
   147             buffer = aParser.iContent->AllocLC();
       
   148             iResponse->iContentIDs.AppendL( buffer );
       
   149             CleanupStack::Pop(); // buffer
       
   150             break;
       
   151         case ETransactionIdState:
       
   152             buffer = aParser.iContent->AllocLC();
       
   153             iResponse->iTransTrackIDs.AppendL( buffer );
       
   154             CleanupStack::Pop(); // buffer
       
   155             break;
       
   156         }
       
   157     }