wmdrm/camese/wmdrmdlaapp/src/wmdrmdlaappservicesession.cpp
changeset 0 95b198f216e5
child 70 2625ef7905cb
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 class for WMDRM DLA App Service Session
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "wmdrmdlaappui.h"
       
    21 #include "wmdrmdlabrowserview.h"
       
    22 #include "wmdrmdlaappservicesession.h"
       
    23 #include "wmdrmdlaappconstants.h"
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KSanityDataLengthLow = 0;
       
    27 const TInt KSanityDataLengthHigh = KMaxTInt32;
       
    28 
       
    29 // ============================= LOCAL FUNCTIONS ==============================
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // SanitizeL
       
    33 // Performs a sanity check on length parameters
       
    34 // ----------------------------------------------------------------------------
       
    35 //
       
    36 LOCAL_C void SanitizeL( TInt aParam )
       
    37     {
       
    38     if ( aParam <= KSanityDataLengthLow || aParam > KSanityDataLengthHigh )
       
    39         {
       
    40         User::Leave( KErrArgument );
       
    41         }
       
    42     }
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CWmDrmDlaAppServiceSession::CWmDrmDlaAppServiceSession
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CWmDrmDlaAppServiceSession::CWmDrmDlaAppServiceSession()
       
    51     {
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CWmDrmDlaAppServiceSession::~CWmDrmDlaAppServiceSession
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CWmDrmDlaAppServiceSession::~CWmDrmDlaAppServiceSession()
       
    59     {
       
    60     delete iWait;
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CWmDrmDlaAppServiceSession::LicenseReceived
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CWmDrmDlaAppServiceSession::LicenseReceived()
       
    69     {
       
    70     //License received, stop waiting and complete post-service
       
    71     if ( iWait->IsStarted() )
       
    72         {
       
    73         iWait->AsyncStop();
       
    74         }
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CWmDrmDlaAppServiceSession::ServiceL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CWmDrmDlaAppServiceSession::ServiceL( const RMessage2& aMessage )
       
    82     {
       
    83     switch ( aMessage.Function() )
       
    84         {
       
    85         case ESetIAP:
       
    86             SetIapL( aMessage );
       
    87             break;
       
    88         
       
    89         case EPost:
       
    90             PostL( aMessage );
       
    91             break;
       
    92         
       
    93         case EGetLicenseResponseSize:
       
    94             LicenseResponseSizeL( aMessage );        
       
    95             break;
       
    96             
       
    97         case EGetLicenseResponse:
       
    98             LicenseResponseL( aMessage );        
       
    99             break;    
       
   100             
       
   101         default:
       
   102              CAknAppServiceBase::ServiceL( aMessage );
       
   103              break;
       
   104         }
       
   105      }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CWmDrmDlaAppServiceSession::SetIapL
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 void CWmDrmDlaAppServiceSession::SetIapL( const RMessage2& aMessage )
       
   112     {
       
   113     TInt iap( 0 );
       
   114     TPckg<TInt> iapPckg( iap );
       
   115     
       
   116     SanitizeL( aMessage.GetDesLength( 0 ) );
       
   117     TInt size = aMessage.GetDesLength( 0 );
       
   118     if ( size != sizeof( TInt ) )
       
   119         {
       
   120         User::Leave( KErrArgument );
       
   121         }
       
   122     aMessage.ReadL( 0, iapPckg );
       
   123     
       
   124     BrowserView()->SetIAP( iap );
       
   125     
       
   126     CompleteMessage( aMessage, KErrNone );
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CWmDrmDlaAppServiceSession::PostL
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CWmDrmDlaAppServiceSession::PostL( const RMessage2& aMessage )
       
   134     {
       
   135     HBufC* postUrl( NULL );
       
   136     TPtr ptr16( NULL, 0 );
       
   137     HBufC8* postContentType( NULL );
       
   138     HBufC8* postData( NULL );
       
   139     HBufC8* postContentBoundary( NULL );
       
   140     TPtr8 ptr8( NULL, 0 );
       
   141     
       
   142     SanitizeL( aMessage.GetDesLength( 0 ) );
       
   143     postUrl = HBufC::NewLC( aMessage.GetDesLength( 0 ) );
       
   144     ptr16.Set( postUrl->Des() );
       
   145     aMessage.ReadL( 0, ptr16 );
       
   146     
       
   147     SanitizeL( aMessage.GetDesLength( 1 ) );
       
   148     postContentType = HBufC8::NewLC( aMessage.GetDesLength( 1 ) );
       
   149     ptr8.Set( postContentType->Des() );
       
   150     aMessage.ReadL( 1, ptr8 );
       
   151 
       
   152     SanitizeL( aMessage.GetDesLength( 2 ) );
       
   153     postData = HBufC8::NewLC( aMessage.GetDesLength( 2 ) );
       
   154     ptr8.Set( postData->Des() );
       
   155     aMessage.ReadL( 2, ptr8 );    
       
   156 
       
   157     SanitizeL( aMessage.GetDesLength( 3 ) );
       
   158     postContentBoundary = HBufC8::NewLC( aMessage.GetDesLength( 3 ) );
       
   159     ptr8.Set( postContentBoundary->Des() );
       
   160     aMessage.ReadL( 3, ptr8 );
       
   161     
       
   162     BrowserView()->PostL( this, 
       
   163                           *postUrl, 
       
   164                           *postContentType, 
       
   165                           *postData, 
       
   166                           *postContentBoundary );
       
   167     
       
   168     CleanupStack::PopAndDestroy( 4, postUrl ); //postContentBoundary, postData,
       
   169                                                //postContentType, postUrl
       
   170     
       
   171     if ( !iWait )
       
   172         {
       
   173         iWait = new (ELeave) CActiveSchedulerWait;
       
   174         }
       
   175     //Wait until license is received
       
   176     iWait->Start();
       
   177     
       
   178     CompleteMessage( aMessage, KErrNone );
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CWmDrmDlaAppServiceSession::LicenseResponseSizeL
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CWmDrmDlaAppServiceSession::LicenseResponseSizeL( 
       
   186     const RMessage2& aMessage )
       
   187     {
       
   188     TInt err( KErrNone );
       
   189     
       
   190     HBufC8* licenseResponse( BrowserView()->LicenseResponse() );
       
   191     if ( licenseResponse )
       
   192         {
       
   193         TInt licenseSize( licenseResponse->Size() );
       
   194         aMessage.WriteL( 0, TPckg<TInt>( licenseSize ) );
       
   195         }
       
   196     else
       
   197         {
       
   198         err = KErrArgument;
       
   199         }
       
   200     
       
   201     CompleteMessage( aMessage, err );
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CWmDrmDlaAppServiceSession::LicenseResponseL
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CWmDrmDlaAppServiceSession::LicenseResponseL( const RMessage2& aMessage )
       
   209     {
       
   210     TInt err( KErrNone );
       
   211     
       
   212     HBufC8* licenseResponse( BrowserView()->LicenseResponse() );
       
   213     if ( licenseResponse )
       
   214         {
       
   215         aMessage.WriteL( 0, *licenseResponse );
       
   216         }
       
   217     else
       
   218         {
       
   219         err = KErrArgument;
       
   220         }
       
   221     
       
   222     CompleteMessage( aMessage, err );
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CWmDrmDlaAppServiceSession::CompleteMessage
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CWmDrmDlaAppServiceSession::CompleteMessage( 
       
   230     const RMessage2& aMessage,
       
   231     TInt aError)
       
   232     {
       
   233     if ( !aMessage.IsNull() )
       
   234         {
       
   235         aMessage.Complete( aError );
       
   236         }
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CWmDrmDlaAppServiceSession::BrowserView
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 CWmDrmDlaBrowserView* CWmDrmDlaAppServiceSession::BrowserView()
       
   244     {
       
   245     return ((CWmDrmDlaAppUi*)CEikonEnv::Static()->EikAppUi())->BrowserView();
       
   246     }