upnpmediaserver/contentdirectoryservice/src/dlna/upnphttpdataservetransaction.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
       
     1 /** @file
       
     2  * Copyright (c) 2009 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:  CUpnpHttpDataServeTransaction implementation.
       
    15  *
       
    16  */
       
    17 #include "upnphttpdataservetransaction.h"
       
    18 #include "upnpdlnafilter.h"
       
    19 #include "upnpdlnafilterheaders.h"
       
    20 #include "upnperrors.h"
       
    21 #include "upnpcons.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // CUpnpHttpDataServeTransaction::NewL
       
    25 // 
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CUpnpHttpDataServeTransaction* CUpnpHttpDataServeTransaction::NewL( 
       
    29         CUpnpDlnaFilter& aClientContext, const TInetAddr& aSender, const TDesC8& aUri )
       
    30     {
       
    31     CUpnpHttpDataServeTransaction* self = 
       
    32         new (ELeave) CUpnpHttpDataServeTransaction( aClientContext );
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL( aSender, aUri );
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }    
       
    38     
       
    39 // ---------------------------------------------------------------------------
       
    40 // CUpnpHttpDataServeTransaction::ConstructL
       
    41 // 
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 void CUpnpHttpDataServeTransaction::ConstructL( 
       
    45     const TInetAddr& aSender, const TDesC8& aSenderUri )
       
    46     {
       
    47     iFilterHeaders = CUpnpDlnaFilterHeaders::NewL( );
       
    48     iSender = aSender;
       
    49     iSenderUri = aSenderUri.AllocL();
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CUpnpHttpDataServeTransaction::FilterHeaders
       
    54 // 
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CUpnpDlnaFilterHeaders& CUpnpHttpDataServeTransaction::FilterHeaders()
       
    58     {
       
    59     return *iFilterHeaders;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CUpnpHttpDataServeTransaction::CUpnpHttpDataServeTransaction
       
    64 // 
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CUpnpHttpDataServeTransaction::CUpnpHttpDataServeTransaction( CUpnpDlnaFilter& aClientContext )
       
    68     : iClientContext( aClientContext )
       
    69     {        }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CUpnpHttpDataServeTransaction::~CUpnpHttpDataServeTransaction
       
    73 // 
       
    74 // ---------------------------------------------------------------------------
       
    75 //    
       
    76 CUpnpHttpDataServeTransaction::~CUpnpHttpDataServeTransaction()
       
    77     {
       
    78     delete iFilterHeaders;
       
    79     delete iSenderUri;
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CUpnpHttpDataServeTransaction::OnCallbackL
       
    84 // 
       
    85 // ---------------------------------------------------------------------------
       
    86 //    
       
    87 void CUpnpHttpDataServeTransaction::OnCallbackL( TUpnpHttpServerEvent aEvent )
       
    88     {
       
    89     TRAPD( err, DoCallbackL( aEvent ) );
       
    90     if ( err )
       
    91         {
       
    92         SetHttpCode( err );
       
    93         }
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CUpnpHttpDataServeTransaction::IsOnFlyTransCoded
       
    98 // ---------------------------------------------------------------------------
       
    99 //  
       
   100 TBool CUpnpHttpDataServeTransaction::IsOnFlyTransCoded()
       
   101     {
       
   102     return iIsOnFlyTransCoded;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CUpnpHttpDataServeTransaction::SenderUri
       
   107 // 
       
   108 // ---------------------------------------------------------------------------
       
   109 //    
       
   110 const TDesC8& CUpnpHttpDataServeTransaction::SenderUri()
       
   111     {
       
   112     return *iSenderUri;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CUpnpHttpDataServeTransaction::PathWithNewMethodL
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //  
       
   120 HBufC16*  CUpnpHttpDataServeTransaction::PathWithNewMethodL()
       
   121     {
       
   122     return iPathWithNewMethod.AllocL();
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CUpnpHttpDataServeTransaction::DoCallbackL
       
   127 // 
       
   128 // ---------------------------------------------------------------------------
       
   129 //  
       
   130 void CUpnpHttpDataServeTransaction::DoCallbackL( TUpnpHttpServerEvent aEvent )
       
   131     {
       
   132     switch ( aEvent )
       
   133         {
       
   134         case EOnRequestStart:
       
   135             {
       
   136             // 1. Format request file path
       
   137             //  
       
   138             
       
   139             TRAPD( error, iClientContext.FormatPathL( this, iPathWithNewMethod ) );
       
   140            
       
   141             if ( error != KErrNone )
       
   142                 {
       
   143                 SetHttpCode( error );
       
   144                 }
       
   145             else if ( iPathWithNewMethod.Length() == 0 )
       
   146                 {
       
   147                 SetHttpCode( -EHttpNotFound );
       
   148                 // Bad name, so such file doesn't exist and cannot be returned.
       
   149                 }
       
   150             else
       
   151                 {
       
   152                 _LIT( KTranscodedTag, "?transcoded=true");
       
   153                 if( iPathWithNewMethod.Find(KTranscodedTag()) >= 0 )
       
   154                     {
       
   155                     iIsOnFlyTransCoded = ETrue;
       
   156                     TFileName fileName(iPathWithNewMethod);
       
   157                     iPathWithNewMethod.Zero();
       
   158                     iPathWithNewMethod.Append(
       
   159                          fileName.Mid(0,fileName.Find(KTranscodedTag())) );
       
   160                     }
       
   161                 error = iClientContext.AuthorizeRequestL( iPathWithNewMethod, iSender );
       
   162                 if ( error == KErrNone )
       
   163                     {
       
   164                     RFile file;
       
   165                     if ( file.Open( iClientContext.FileSession(),
       
   166                                     iPathWithNewMethod,
       
   167                                     EFileShareReadersOnly | EFileRead ) == KErrNone ) 
       
   168                         {
       
   169                         SetDataSourceL( file );
       
   170                         }
       
   171                     else
       
   172                         {
       
   173                         SetHttpCode( -EHttpNotFound );
       
   174                         }
       
   175                     }
       
   176                 else
       
   177                     {
       
   178                     SetHttpCode( error );
       
   179                     }
       
   180                 }                
       
   181             break;
       
   182             }
       
   183         case EOnComplete:
       
   184             break;  
       
   185         case EOnResponseStart:
       
   186             InitializeFilterHeadersL();
       
   187             SetHttpCode( iClientContext.PrepareHeaderL( *this ) );
       
   188             break;
       
   189         default:
       
   190             break;
       
   191         }            
       
   192     }
       
   193 
       
   194 void CUpnpHttpDataServeTransaction::InitializeFilterHeadersL()
       
   195     {
       
   196     //Copy current KHdrContentFeatures and KHdrTransferMode to filterHeaders
       
   197     if ( QueryRequestHeader( UpnpDLNA::KHdrContentFeatures ).Length() > 0 )
       
   198         {
       
   199         iFilterHeaders->AddHeaderL( UpnpDLNA::KHdrContentFeatures,
       
   200                 QueryRequestHeader( UpnpDLNA::KHdrContentFeatures ) );            
       
   201         }
       
   202     if ( QueryRequestHeader( UpnpDLNA::KHdrTransferMode ).Length() > 0 )
       
   203         {
       
   204         iFilterHeaders->AddHeaderL( UpnpDLNA::KHdrTransferMode,
       
   205                 QueryRequestHeader( UpnpDLNA::KHdrTransferMode ) );            
       
   206         }
       
   207     }
       
   208