omadrm/drmengine/roap/src/JoinDomainRespParser.cpp
changeset 0 95b198f216e5
child 84 b09186059647
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 "OmaCrypto.h"
       
    24 #include "CmlaCrypto.h"
       
    25 #include "RoapParser.h"
       
    26 #include "JoinDomainResp.h"
       
    27 #include "JoinDomainRespParser.h"
       
    28 
       
    29 using namespace Roap;
       
    30 
       
    31 // LOCAL CONSTANTS AND MACROS
       
    32 _LIT8(KStatus, "status");
       
    33 _LIT8(KErrorUrl, "errorRedirectURL");
       
    34 _LIT8(KAlgorithmAttr, "Algorithm");
       
    35 _LIT8(KInfinite, "Infinite");
       
    36 _LIT8(KId, "Id");
       
    37 _LIT8(KHashChainSupport, "HashChainSupport");
       
    38 _LIT8(KType, "type");
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // TJoinDomainRespParser::TJoinDomainRespParser
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 TJoinDomainRespParser::TJoinDomainRespParser(
       
    47     CJoinDomainResp* aResponse)
       
    48     {
       
    49     iResponse = aResponse;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // TJoinDomainRespParser::?member_function
       
    54 // ?implementation_description
       
    55 // (other items were commented in a header).
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void TJoinDomainRespParser::OnStartElementL(
       
    59     CRoapParser& aParser,
       
    60     TInt aState,
       
    61     const RTagInfo& /*aElement*/,
       
    62     const RAttributeArray& aAttributes)
       
    63     {
       
    64     HBufC8* buffer = NULL;
       
    65 
       
    66     switch (aState)
       
    67         {
       
    68         case EJoinDomainResponseState:
       
    69             buffer = aParser.GetAttributeValueL(aAttributes, KStatus);
       
    70             if (buffer != NULL)
       
    71                 {
       
    72                 iResponse->iStatus = aParser.ConvertRoapStatus(*buffer);
       
    73                 delete buffer;
       
    74                 }
       
    75             else
       
    76                 {
       
    77                 iResponse->iStatus = EUnknownStatus;
       
    78                 }
       
    79                 
       
    80             iResponse->iErrorUrl = aParser.GetAttributeValueL(aAttributes, KErrorUrl);
       
    81             break;
       
    82         case EDomainKeyEncryptionMethodState:
       
    83             buffer = aParser.GetAttributeValueL(aAttributes, KAlgorithmAttr);
       
    84             if (buffer )
       
    85                 {
       
    86                 iResponse->iTransportScheme =
       
    87                     CmlaCrypto::AlgorithmIdToTransportScheme(*buffer);
       
    88                 delete buffer;
       
    89                 }
       
    90             break;
       
    91         case EDomainKeyEncKeyState:
       
    92             buffer = aParser.GetAttributeValueL(aAttributes, KId);
       
    93             if ( buffer )
       
    94                 {
       
    95                 CleanupStack::PushL(buffer);
       
    96                 iResponse->iDomainKeyIDs.AppendL(buffer);
       
    97                 CleanupStack::Pop();
       
    98                 }
       
    99         case EExtensionState:
       
   100             buffer = aParser.GetAttributeValueL(aAttributes, KType );
       
   101             if(buffer != NULL)
       
   102                 {
       
   103                 if(buffer->Find(KHashChainSupport) >= KErrNone)
       
   104                     {
       
   105                     iResponse->iHashChainSupport = ETrue;
       
   106                     }
       
   107                 delete buffer;
       
   108                 }
       
   109         break;
       
   110         }
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // TJoinDomainRespParser::?member_function
       
   115 // ?implementation_description
       
   116 // (other items were commented in a header).
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void TJoinDomainRespParser::OnEndElementL(
       
   120     CRoapParser& aParser,
       
   121     TInt aState,
       
   122     const RTagInfo& /*aElement*/)
       
   123     {
       
   124     HBufC8* buffer = NULL;
       
   125     
       
   126     if (!aParser.iContent)
       
   127         {
       
   128         return;
       
   129         }
       
   130 
       
   131     switch (aState)
       
   132         {
       
   133         case ECertificateState:
       
   134             buffer = Base64DecodeL(*aParser.iContent);
       
   135             CleanupStack::PushL(buffer);
       
   136             iResponse->iCertificateChain.AppendL(buffer);
       
   137             CleanupStack::Pop(); //buffer
       
   138             break;
       
   139         case EOcspResponseState:
       
   140             buffer = Base64DecodeL(*aParser.iContent);
       
   141             CleanupStack::PushL(buffer);
       
   142             iResponse->iOcspResponse.AppendL(buffer);
       
   143             CleanupStack::Pop(); // buffer
       
   144             break;
       
   145         case ERiIdState:
       
   146             buffer = Base64DecodeL(*aParser.iContent);
       
   147             if ( buffer->Length() > SHA1_HASH )
       
   148                 {
       
   149                 delete buffer;
       
   150                 buffer = NULL;
       
   151                 User::Leave( KErrCorrupt );
       
   152                 }
       
   153             iResponse->iRiId.Copy(*buffer);
       
   154             delete buffer;
       
   155             break;
       
   156         case ERiIdJoinDomainResponseState:
       
   157             buffer = Base64DecodeL(*aParser.iContent);
       
   158             if ( buffer->Length() > SHA1_HASH )
       
   159                 {
       
   160                 delete buffer;
       
   161                 buffer = NULL;
       
   162                 User::Leave( KErrCorrupt );
       
   163                 }
       
   164             iResponse->iDomainKeyRiId.Copy(*buffer);
       
   165             delete buffer;
       
   166             break;
       
   167         case EDeviceIdState:
       
   168             buffer = Base64DecodeL(*aParser.iContent);
       
   169             if ( buffer->Length() > SHA1_HASH )
       
   170                 {
       
   171                 delete buffer;
       
   172                 buffer = NULL;
       
   173                 User::Leave( KErrCorrupt );
       
   174                 }
       
   175             iResponse->iDeviceId.Copy(*buffer);
       
   176             delete buffer;
       
   177             break;
       
   178         case ESignatureState:
       
   179             iResponse->iSignature = Base64DecodeL( *aParser.iContent );
       
   180             break;
       
   181         case EEncKeyState:
       
   182             buffer = Base64DecodeL( *aParser.iContent );
       
   183             CleanupStack::PushL( buffer );
       
   184             iResponse->iDomainKeys.AppendL( buffer );
       
   185             CleanupStack::Pop(); // buffer
       
   186             break;
       
   187         case ENotAfterState:
       
   188             if ( aParser.iContent )
       
   189                 {
       
   190                 if (aParser.iContent->CompareF( KInfinite() ) == KErrNone )
       
   191                     {
       
   192                     iResponse->iDomainExpiration = Time::NullTTime();
       
   193                     }
       
   194                 else
       
   195                     {
       
   196                     iResponse->iDomainExpiration = iResponse->Iso8601ToTime(
       
   197                         *aParser.iContent);   
       
   198                     }
       
   199                 }
       
   200             break;
       
   201         case EMacJoinDomainResponseState:
       
   202             buffer = Base64DecodeL( *aParser.iContent );
       
   203             CleanupStack::PushL( buffer );
       
   204             iResponse->iMacs.AppendL( buffer );
       
   205             CleanupStack::Pop(); // buffer
       
   206             break;
       
   207         }
       
   208     }
       
   209 
       
   210 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   211 
       
   212 // -----------------------------------------------------------------------------
       
   213 // ?function_name implements...
       
   214 // ?implementation_description.
       
   215 // Returns: ?value_1: ?description
       
   216 //          ?value_n: ?description
       
   217 //                    ?description
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 
       
   221 //  End of File