upnp/upnpstack/serviceframework/src/upnphttpservertransactionhandler.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2  * Copyright (c) 2005-2006 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:  CUpnpHttpServerTransactionHandler implementation.
       
    15  *
       
    16  */
       
    17 // INCLUDES
       
    18 #include <bautils.h> 
       
    19 
       
    20 #include "upnphttpservertransactionhandler.h"
       
    21 #include "upnpstring.h"
       
    22 #include "upnphttpmessage.h"
       
    23 #include "upnpicon.h"
       
    24 
       
    25 #include "upnphttpservertransactiondescription.h"
       
    26 #include "upnpdevicedescriptionrequest.h"
       
    27 #include "upnpdevicedescriptionprovider.h"
       
    28 #include "upnpdeviceimplementationbase.h"
       
    29 
       
    30 
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CUpnpHttpServerTransactionHandler::CUpnpHttpServerTransactionHandler
       
    37 // C++ default constructor.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CUpnpHttpServerTransactionHandler::CUpnpHttpServerTransactionHandler(
       
    41         CUpnpDeviceImplementationBase& aDevice ) :
       
    42     iDevice( aDevice )
       
    43 
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CUpnpHttpServerTransactionHandler::~CUpnpHttpServerTransactionHandler
       
    49 // C++ default destructor.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CUpnpHttpServerTransactionHandler::~CUpnpHttpServerTransactionHandler()
       
    53     {
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CUpnpHttpServerTransactionHandler::NewLC
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CUpnpHttpServerTransactionHandler* CUpnpHttpServerTransactionHandler::NewLC(
       
    62         CUpnpDeviceImplementationBase& aDevice )
       
    63     {
       
    64     CUpnpHttpServerTransactionHandler* self =
       
    65             new ( ELeave ) CUpnpHttpServerTransactionHandler( aDevice );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();
       
    68     return self;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CUpnpHttpServerTransactionHandler::NewL
       
    73 // Two-phased constructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CUpnpHttpServerTransactionHandler* CUpnpHttpServerTransactionHandler::NewL(
       
    77         CUpnpDeviceImplementationBase& aDevice )
       
    78     {
       
    79     CUpnpHttpServerTransactionHandler* self =
       
    80             CUpnpHttpServerTransactionHandler::NewLC( aDevice );
       
    81     CleanupStack::Pop( self );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CUpnpHttpServerTransactionHandler::ConstructL
       
    87 // EPOC default constructor for performing 2nd stage construction.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CUpnpHttpServerTransactionHandler::ConstructL()
       
    91     {   
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 //  CUpnpHttpServerTransactionHandler::NewTransactionL
       
    97 //
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CUpnpHttpServerTransactionHandler::NewTransactionL( 
       
   101     const TDesC8& aMethod, const TDesC8& aUri, 
       
   102     const TInetAddr& aSender, CUpnpHttpServerTransaction*& aResultTrans )
       
   103     {
       
   104     _LIT8( KGet, "GET" );
       
   105     _LIT8( KHead, "HEAD" );
       
   106     if ( (aMethod.CompareF(KGet)==0) || (aMethod.CompareF(KHead)==0) )
       
   107         {
       
   108         aResultTrans = CUpnpHttpServerTransactionDescription::NewL( *this, aSender, aUri );
       
   109         }
       
   110     else
       
   111         {
       
   112         User::Leave( KErrGeneral );//bad request
       
   113         }
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 //  CUpnpHttpServerTransactionHandler::GetFileL
       
   119 //
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TInt CUpnpHttpServerTransactionHandler::GetFileL( RFile& aFile,
       
   123         const TDesC8& aUri, const TInetAddr& aInetAdress )
       
   124     {
       
   125     
       
   126     CUpnpDeviceDescriptionRequest* request = CUpnpDeviceDescriptionRequest::NewL( aUri, aInetAdress );    
       
   127     TInt error = KErrNone;
       
   128     
       
   129     switch ( MatchType( aUri ) )
       
   130         {
       
   131         case EDevice:
       
   132             error = iDevice.DescritptionProvider().OnDeviceDescription( *request );
       
   133             break;        
       
   134         case EService:
       
   135             error = iDevice.DescritptionProvider().OnServiceDescription( *request );
       
   136             break;        
       
   137         case EIcon:
       
   138             error = iDevice.DescritptionProvider().OnIcon( *request );
       
   139             break;        
       
   140         default:
       
   141             error = -EHttpNotFound;            
       
   142             break;
       
   143         }
       
   144     delete request;
       
   145     request = NULL;
       
   146     
       
   147     if( KErrNone == error )
       
   148         {
       
   149         if ( KErrNone != iDevice.DescritptionProvider().GetFile( aUri, aFile ) )
       
   150             {
       
   151             error = -EHttpNotFound;
       
   152             }
       
   153         }
       
   154     else
       
   155         {
       
   156         error = -EHttpNotFound;
       
   157         }
       
   158     
       
   159     return error;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 //  CUpnpHttpServerTransactionHandler::MatchType
       
   164 //
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 CUpnpHttpServerTransactionHandler::TDescriptionType 
       
   168               CUpnpHttpServerTransactionHandler::MatchType( const TDesC8& aUri )
       
   169     {
       
   170     if ( aUri.CompareF( iDevice.DescriptionUrl() ) == 0 )
       
   171         {
       
   172         return EDevice;
       
   173         }
       
   174 
       
   175     //1st check if url is service url
       
   176     RPointerArray<CUpnpService> servList =
       
   177                  iDevice.ServiceList();
       
   178     TInt count = servList.Count();
       
   179     for( TInt index = 0; index < count; index++ )
       
   180         {
       
   181         if( servList[ index ]->ServiceDescriptionUrl().CompareF( aUri ) == 0 )
       
   182             {
       
   183             return EService;
       
   184             }
       
   185         }
       
   186     //next check icon list
       
   187     RPointerArray<CUpnpIcon> iconList =
       
   188                  iDevice.Icons();
       
   189     count = iconList.Count();
       
   190     for( TInt index2 = 0; index2 < count; index2++ )
       
   191         {
       
   192         if( iconList[ index2 ]->Url().CompareF( aUri ) == 0 )
       
   193             {
       
   194             return EIcon;
       
   195             }
       
   196         }
       
   197     return ENotFound;
       
   198     }
       
   199 
       
   200 
       
   201 //  End of File