wmdrm/camese/wmdrmdla/src/wmdrmdlaparser.cpp
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of the WMDRM DLA Parser
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <xml/xmlframeworkconstants.h>
       
    21 #include "wmdrmdlaparser.h"
       
    22 
       
    23 #define _LOGGING_FILE L"wmdrmdla.txt"
       
    24 #include "logfn.h"
       
    25 
       
    26 // CONSTANTS
       
    27 _LIT8( KLaInfoTag8, "lainfo" );
       
    28 _LIT8( KTIDTag8, "tid" );
       
    29 _LIT8( KContentUrlTag8, "contenturl" );
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // CWmDrmDlaParser::NewL
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 CWmDrmDlaParser* CWmDrmDlaParser::NewL()
       
    36     {
       
    37     LOGFN( "CWmDrmDlaParser::NewL" );
       
    38     CWmDrmDlaParser* self = new (ELeave) CWmDrmDlaParser();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ----------------------------------------------------------------------------
       
    46 // CWmDrmDlaParser::CWmDrmDlaParser
       
    47 // ----------------------------------------------------------------------------
       
    48 //
       
    49 CWmDrmDlaParser::CWmDrmDlaParser()
       
    50     {
       
    51     LOGFN( "CWmDrmDlaParser::CWmDrmDlaParser" );
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // CWmDrmDlaParser::~CWmDrmDlaParser
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 CWmDrmDlaParser::~CWmDrmDlaParser()
       
    59     {
       
    60     LOGFN( "CWmDrmDlaParser::~CWmDrmDlaParser" );
       
    61     delete iParser;
       
    62     delete iBuffer;
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // CWmDrmDlaParser::ConstructL
       
    67 // ----------------------------------------------------------------------------
       
    68 //
       
    69 void CWmDrmDlaParser::ConstructL()
       
    70     {
       
    71     LOGFN( "CWmDrmDlaParser::ConstructL" );
       
    72     // Mime type of the parsed document
       
    73     _LIT8( KXmlMimeType, "text/xml" );
       
    74     // Construct the parser object
       
    75     iParser = Xml::CParser::NewL( KXmlMimeType, *this );
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // CWmDrmDlaParser::ProcessLicenseResponse
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 TInt CWmDrmDlaParser::ProcessLicenseResponse(
       
    83     const TDesC8& aLicenseResponse,
       
    84     HBufC8*& aTID,
       
    85     HBufC8*& aContentURL)
       
    86     {
       
    87     TInt error = KErrNone;
       
    88     
       
    89     LOGFNR( "CWmDrmDlaParser::ProcessLicenseResponse", error );
       
    90     
       
    91     // Find beginning of XML document ('<')
       
    92     TInt pos = aLicenseResponse.Locate( '<' );
       
    93     if ( pos != KErrNotFound )
       
    94       {
       
    95       iContentUrl = &aContentURL;
       
    96       iTID = &aTID;
       
    97       iErrorCode = KErrNone;
       
    98       TPtrC8 ptrUrl = aLicenseResponse.Mid( pos );
       
    99       TRAP( error, Xml::ParseL( *iParser, ptrUrl ) );
       
   100       if ( !error )
       
   101         {
       
   102         error = iErrorCode;
       
   103         }
       
   104 
       
   105       iTID = NULL;
       
   106       iContentUrl = NULL;
       
   107 
       
   108       delete iServerUrl;
       
   109       iServerUrl = NULL;
       
   110       }
       
   111     else
       
   112       {
       
   113       error = KErrCorrupt;
       
   114       }
       
   115     return error;
       
   116     }
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CWmDrmDlaParser::GetLicenseServerURLFromDRMHeader
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 TInt CWmDrmDlaParser::GetLicenseServerURLFromDRMHeader(
       
   123     const TDesC8& aDrmHeader,
       
   124     HBufC8*& aServerURL )
       
   125     {
       
   126     TInt error( KErrNone );
       
   127     
       
   128     LOGFNR( "CWmDrmDlaParser::GetLicenseServerURLFromDRMHeader", error );
       
   129     
       
   130     // Find beginning of XML document ('<')
       
   131     TInt pos = aDrmHeader.Locate( '<' );
       
   132     if ( pos != KErrNotFound )
       
   133         {
       
   134         iServerUrl = &aServerURL;
       
   135         iErrorCode = KErrNone;
       
   136         TPtrC8 ptrUrl = aDrmHeader.Mid( pos );
       
   137         TRAP( error, Xml::ParseL( *iParser, ptrUrl ) );
       
   138         if ( !error )
       
   139             {
       
   140             error = iErrorCode;
       
   141             }
       
   142 
       
   143         iServerUrl = NULL;
       
   144 
       
   145         delete iTID;
       
   146         iTID = NULL;
       
   147 
       
   148         delete iContentUrl;
       
   149         iContentUrl = NULL;
       
   150         }
       
   151     else
       
   152         {
       
   153         error = KErrCorrupt;
       
   154         }
       
   155 
       
   156     return error;
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CWmDrmDlaParser::OnStartDocumentL
       
   161 // From MContentHandler
       
   162 // ----------------------------------------------------------------------------
       
   163 //
       
   164 void CWmDrmDlaParser::OnStartDocumentL(
       
   165     const Xml::RDocumentParameters& /*aDocParam*/,
       
   166     TInt /*aErrorCode*/ )
       
   167     {
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------------------------------
       
   171 // CWmDrmDlaParser::OnEndDocumentL
       
   172 // From MContentHandler
       
   173 // ----------------------------------------------------------------------------
       
   174 //
       
   175 void CWmDrmDlaParser::OnEndDocumentL( TInt /*aErrorCode*/ )
       
   176     {
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------------------------------
       
   180 // CWmDrmDlaParser::OnStartElementL
       
   181 // From MContentHandler
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 void CWmDrmDlaParser::OnStartElementL(
       
   185     const Xml::RTagInfo& /*aElement*/,
       
   186     const Xml::RAttributeArray& /*aAttributes*/,
       
   187     TInt /*aErrorCode*/ )
       
   188     {
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CWmDrmDlaParser::OnEndElementL
       
   193 // From MContentHandler
       
   194 // ----------------------------------------------------------------------------
       
   195 //
       
   196 void CWmDrmDlaParser::OnEndElementL(
       
   197     const Xml::RTagInfo& aElement,
       
   198     TInt aErrorCode)
       
   199     {
       
   200     User::LeaveIfError( aErrorCode );
       
   201     if ( !aElement.LocalName().DesC().CompareF( KLaInfoTag8 ) )
       
   202         {
       
   203         *iServerUrl = iBuffer;
       
   204         iBuffer = NULL;
       
   205         }
       
   206     else if ( !aElement.LocalName().DesC().CompareF( KTIDTag8 ) )
       
   207         {
       
   208         *iTID = iBuffer;
       
   209         iBuffer = NULL;
       
   210         }
       
   211     else if ( !aElement.LocalName().DesC().CompareF( KContentUrlTag8 ) )
       
   212         {
       
   213         *iContentUrl = iBuffer;
       
   214         iBuffer = NULL;
       
   215         }
       
   216     else
       
   217         {
       
   218         delete iBuffer;
       
   219         iBuffer = NULL;
       
   220         }
       
   221     }
       
   222 
       
   223 // ----------------------------------------------------------------------------
       
   224 // CWmDrmDlaParser::OnContentL
       
   225 // From MContentHandler
       
   226 // ----------------------------------------------------------------------------
       
   227 //
       
   228 void CWmDrmDlaParser::OnContentL( const TDesC8& aBytes, TInt /*aErrorCode*/ )
       
   229     {
       
   230     if ( !iBuffer )
       
   231         {
       
   232         iBuffer = aBytes.AllocL();
       
   233         }
       
   234     else
       
   235         {
       
   236         iBuffer = iBuffer->ReAllocL( iBuffer->Length() + aBytes.Length() );
       
   237         iBuffer->Des().Append( aBytes );
       
   238         }
       
   239  
       
   240    }
       
   241 
       
   242 // ----------------------------------------------------------------------------
       
   243 // CWmDrmDlaParser::OnStartPrefixMappingL
       
   244 // From MContentHandler
       
   245 // ----------------------------------------------------------------------------
       
   246 //
       
   247 void CWmDrmDlaParser::OnStartPrefixMappingL(
       
   248     const RString& /*aPrefix*/,
       
   249     const RString& /*aUri*/,
       
   250     TInt /*aErrorCode*/ )
       
   251     {
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CWmDrmDlaParser::OnEndPrefixMappingL
       
   256 // From MContentHandler
       
   257 // ----------------------------------------------------------------------------
       
   258 //
       
   259 void CWmDrmDlaParser::OnEndPrefixMappingL(
       
   260     const RString& /*aPrefix*/,
       
   261     TInt /*aErrorCode*/ )
       
   262     {
       
   263     }
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CWmDrmDlaParser::OnIgnorableWhiteSpaceL
       
   267 // From MContentHandler
       
   268 // ----------------------------------------------------------------------------
       
   269 //
       
   270 void CWmDrmDlaParser::OnIgnorableWhiteSpaceL(
       
   271     const TDesC8& /*aBytes*/,
       
   272     TInt /*aErrorCode*/ )
       
   273     {
       
   274     }
       
   275 
       
   276 // ----------------------------------------------------------------------------
       
   277 // CWmDrmDlaParser::OnSkippedEntityL
       
   278 // From MContentHandler
       
   279 // ----------------------------------------------------------------------------
       
   280 //
       
   281 void CWmDrmDlaParser::OnSkippedEntityL(
       
   282     const RString& /*aName*/,
       
   283     TInt /*aErrorCode*/ )
       
   284     {
       
   285     }
       
   286 
       
   287 // ----------------------------------------------------------------------------
       
   288 // CWmDrmDlaParser::OnProcessingInstructionL
       
   289 // From MContentHandler
       
   290 // ----------------------------------------------------------------------------
       
   291 //
       
   292 void CWmDrmDlaParser::OnProcessingInstructionL(
       
   293     const TDesC8& /*aTarget*/,
       
   294     const TDesC8& /*aData*/,
       
   295     TInt /*aErrorCode*/ )
       
   296     {
       
   297     }
       
   298 
       
   299 // ----------------------------------------------------------------------------
       
   300 // CWmDrmDlaParser::OnError
       
   301 // From MContentHandler
       
   302 // ----------------------------------------------------------------------------
       
   303 //
       
   304 void CWmDrmDlaParser::OnError( TInt aErrorCode )
       
   305     {
       
   306     iErrorCode = aErrorCode;
       
   307     }
       
   308 
       
   309 // ----------------------------------------------------------------------------
       
   310 // CWmDrmDlaParser::GetExtendedInterface
       
   311 // From MContentHandler
       
   312 // ----------------------------------------------------------------------------
       
   313 //
       
   314 TAny* CWmDrmDlaParser::GetExtendedInterface( const TInt32 /* aUid */ )
       
   315     {
       
   316     return NULL;
       
   317     }