upnpmediaserver/contentdirectoryservice/inc/dlna/upnpdlnafilter.h
branchnew development branch with rendering state machine and other goodies
changeset 38 5360b7ddc251
parent 0 7f85d04be362
equal deleted inserted replaced
32:3785f754ee62 38:5360b7ddc251
     1 /** @file
     1 /** @file
     2  * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). 
     2  * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies  this distribution, and is available 
     6  * which accompanies  this distribution, and is available 
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 #include <e32base.h>
    23 #include <e32base.h>
    24 #include <f32file.h> 
    24 #include <f32file.h> 
    25 #include "upnphttpservertransactioncreator.h"
    25 #include "upnphttpservertransactioncreator.h"
    26 
    26 
    27 class MUpnpContentDirectoryDataFinder;
    27 class MUpnpContentDirectoryDataFinder;
    28 class CUpnpHttpMessage;
       
    29 class CUpnpDlnaProtocolInfo;
    28 class CUpnpDlnaProtocolInfo;
    30 class CUpnpSecurityManager;
    29 class CUpnpSecurityManager;
    31 class CUpnpHttpFileServeTransaction;
    30 class CUpnpHttpDataServeTransaction;
    32 class CUpnpHttpFileReceiveTransaction;
    31 class CUpnpHttpFileReceiveTransaction;
    33 class CUpnpDlnaFilterHeaders;
       
    34 class TUpnpDlnaCorelation;
    32 class TUpnpDlnaCorelation;
    35 
    33 
    36 // CLASS DECLARATION
    34 // CLASS DECLARATION
    37 
    35 
    38 /**
    36 /**
    43         public MUpnpHttpServerTransactionCreator
    41         public MUpnpHttpServerTransactionCreator
    44     {
    42     {
    45 public:
    43 public:
    46     // Public Constructors and destructor
    44     // Public Constructors and destructor
    47 
    45 
       
    46 	/**
       
    47 	 * static constructor.
       
    48 	 * 
       
    49 	 * @param aFinder, MUpnpContentDirectoryDataFinder
       
    50 	 * @param aSecurityManager, instance of CUpnpSecurityManager
       
    51 	 */
       
    52 	IMPORT_C  static CUpnpDlnaFilter* NewL( 
       
    53 		MUpnpContentDirectoryDataFinder* aFinder,
       
    54 		CUpnpSecurityManager* aSecurityManager );
       
    55 	
       
    56 	/**
       
    57 	 * see MUpnpHttpServerTransactionCreator.
       
    58 	 */
       
    59 	IMPORT_C void NewTransactionL(
       
    60 		const TDesC8& aMethod, const TDesC8& aUri, 
       
    61 		const TInetAddr& aSender, 
       
    62 		CUpnpHttpServerTransaction*& aResultTrans );
       
    63 	
       
    64     /**
       
    65      * static constructor.
       
    66      */
       
    67     IMPORT_C static CUpnpDlnaFilter* NewLC( 
       
    68     	MUpnpContentDirectoryDataFinder* aFinder,
       
    69         CUpnpSecurityManager* aSecurityManager );
       
    70 	    
    48     /**
    71     /**
    49      * Destructor.
    72      * Destructor.
    50      */
    73      */
    51     ~CUpnpDlnaFilter();
    74     ~CUpnpDlnaFilter();
    52 
    75     
    53     /**
       
    54      * Two-phased constructor.
       
    55      */
       
    56     static CUpnpDlnaFilter* NewL( MUpnpContentDirectoryDataFinder* aFinder,
       
    57         CUpnpSecurityManager* aSecurityManager );
       
    58 
       
    59     /**
       
    60      * Two-phased constructor.
       
    61      */
       
    62     static CUpnpDlnaFilter* NewLC( MUpnpContentDirectoryDataFinder* aFinder,
       
    63         CUpnpSecurityManager* aSecurityManager );
       
    64 
       
    65     //from MUpnpHttpServerTransactionCreator
       
    66     virtual void NewTransactionL(
       
    67         const TDesC8& aMethod, const TDesC8& aUri, 
       
    68         const TInetAddr& aSender, CUpnpHttpServerTransaction*& aResultTrans );
       
    69 
    76 
    70     //from MUpnpHttpServerTransactionCreator
    77     //from MUpnpHttpServerTransactionCreator
    71 
    78 
    72     /**
    79     /**
    73      * Checks correctness of path to, requested in HTTP message, file and 
    80      * Checks correctness of path to, requested in HTTP message, file and 
    74      *  changes its format to be compliant with Symbian's file system.
    81      *  changes its format to be compliant with Symbian's file system.
    75      * @since Series60 2.6
    82      * @since Series60 2.6
    76      * @param aMsg HTTP message containing file request.
    83      * 
    77      * @param aPathWithNewMethod reference which is filled with formated path 
    84      * @param aTransaction http transaction
       
    85      * @param aPath reference which is filled with formated path 
    78      *  to requested file.
    86      *  to requested file.
    79      **/
    87      **/
    80     void FormatPathL( CUpnpHttpFileServeTransaction *aTransaction, TDes &aPath );
    88     void FormatPathL( CUpnpHttpDataServeTransaction *aTransaction, 
    81 
    89     		TDes &aPath );
    82     /**
    90 
    83      * Add appropriate directives to http header according to DLNA specification
    91     /**
       
    92      * Add appropriate directives to http header according to DLNA 
       
    93      * specification
       
    94      * 
    84      * @param aTransaction http transaction
    95      * @param aTransaction http transaction
    85      * @return KErrNone header prepared successfully, otherwise -EHttpNotFound
    96      * @return KErrNone header prepared successfully,otherwise-EHttpNotFound
    86      *         If DLNA correlations are wrong error from then it returns an error
    97      * If DLNA correlations are wrong error from then it returns an error
    87      */
    98      */
    88     TInt PrepareHeaderL( CUpnpHttpFileServeTransaction &aTransaction );
    99     TInt PrepareHeaderL( CUpnpHttpDataServeTransaction &aTransaction );
    89 
   100 
    90     /**
   101     /**
    91      * Method checks DLNA transferMode for POST messages.
   102      * Method checks DLNA transferMode for POST messages.
    92      * @since Series60 2.6
   103      * @since Series60 2.6
    93      * @param aPostMessage - incoming POST message with upload to be saved in file.
   104      * 
       
   105      * @param aTransaction - incoming POST message with upload to be saved 
       
   106      * in file.
    94      * @return ETrue if POST can be accepted.
   107      * @return ETrue if POST can be accepted.
    95      **/
   108      **/
    96     TInt CheckDLNAPostCorrelationsL(CUpnpHttpFileReceiveTransaction& aTransaction);
   109     TInt CheckDLNAPostCorrelationsL(
    97 
   110     		CUpnpHttpFileReceiveTransaction& aTransaction);
    98     /**
   111 
    99      * Determines download path basing on incomming POST message and media path got
   112     /**
   100      *  from server. Result is saved in iInFilename. 
   113      * Determines download path basing on incomming POST message and media 
       
   114      * path got from server. Result is saved in iInFilename. 
   101      *  If file should not be saved, flag iSaveToFile will be set to EFalse.
   115      *  If file should not be saved, flag iSaveToFile will be set to EFalse.
   102      * @since Series60 2.6
   116      * @since Series60 2.6
   103      * @param aPostMessage - incoming POST message with upload to be saved in file.
   117      * 
       
   118      * @param aTransaction - incoming POST message with upload to be saved 
       
   119      * in file.
   104      * @return download path or NULL in case of error
   120      * @return download path or NULL in case of error
   105      */
   121      */
   106     HBufC* DetermineDownloadPathL(CUpnpHttpFileReceiveTransaction& aTransaction);
   122     HBufC* DetermineDownloadPathL(
   107 
   123     		CUpnpHttpFileReceiveTransaction& aTransaction);
   108     //security manager getter
   124 
       
   125     /**
       
   126      * security manager getter
       
   127      */
   109     CUpnpSecurityManager* SecurityManager();
   128     CUpnpSecurityManager* SecurityManager();
   110     
   129     
   111     //file server session getter        
   130     /**
       
   131      * file server session getter
       
   132      */
   112     RFs& FileSession();
   133     RFs& FileSession();
   113 
   134 
   114     /**
   135     /**
   115      * Check if resource is accessible 
   136      * Check if resource is accessible 
       
   137      * 
   116      * @param aFileName data source file name
   138      * @param aFileName data source file name
   117      * @param aSender sender
   139      * @param aSender sender
   118      * @return KErrNone if resource is accessible, otherwise -EHttpNotFound
   140      * @return KErrNone if resource is accessible, otherwise-EHttpNotFound
   119      */
   141      */
   120     TInt AuthorizeRequestL( const TDesC& aFileName, const TInetAddr& aSender );
   142     TInt AuthorizeRequestL( const TDesC& aFileName, 
   121 
   143     		const TInetAddr& aSender );
   122 public:
   144 
       
   145 private:
   123     // protected
   146     // protected
   124     // Private Constructors
   147     // Private Constructors
   125 
   148 
   126     /**
   149     /**
   127      * Constructor for performing 1st stage construction
   150      * Constructor for performing 1st stage construction
   128      */
   151      */
   129     CUpnpDlnaFilter( MUpnpContentDirectoryDataFinder* aFinder,
   152 	CUpnpDlnaFilter( MUpnpContentDirectoryDataFinder* aFinder,
   130         CUpnpSecurityManager* aSecurityManager );
   153         CUpnpSecurityManager* aSecurityManager );
   131 
   154 
   132     /**
   155     /**
   133      * EPOC default constructor for performing 2nd stage construction
   156      * EPOC default constructor for performing 2nd stage construction
   134      */
   157      */
   135     void ConstructL();
   158     void ConstructL();
   136 
   159 
   137 private:
   160 private:
   138 
   161 
   139     /**
   162     /**
   140      * Find protocolInfo by contentUri (Not by importUri) and extract 3rd field,
   163      * Find protocolInfo by contentUri (Not by importUri) and extract 3rd 
   141      * using ContentDirectory.
   164      * field, using ContentDirectory.
       
   165      * 
   142      * @param aFullContentUri uri to be searched in database
   166      * @param aFullContentUri uri to be searched in database
   143      *       (full value of resource with IP:port prefix).
   167      *       (full value of resource with IP:port prefix).
   144      * @return a3rdhField 3rdhField from protocolInfo (if it is DLNA compatible) which is
   168      * @return a3rdhField 3rdhField from protocolInfo (if it is DLNA 
   145      *       related to founded resource. Ownership is transfered to the caller.
   169      * compatible) which is related to founded resource. 
       
   170      * Ownership is transfered to the caller.
   146      */
   171      */
   147     HBufC8* CUpnpDlnaFilter::ThirdFieldFromCdL( const TDesC8& aContentUri );
   172     HBufC8* CUpnpDlnaFilter::ThirdFieldFromCdL( const TDesC8& aContentUri );
   148 
   173 
   149     /**
   174     /**
   150      * Gets name of file with content for given object's id.
   175      * Gets name of file with content for given object's id.
       
   176      * 
   151      * @param aObjectId id of the ContentDirecotry object holding the content
   177      * @param aObjectId id of the ContentDirecotry object holding the content
   152      * @param aFileName pointer to buffer in which the name of the file will be returned.
   178      * @param aFileName pointer to buffer in which the name of the file will 
   153      *       Buffer for aFileName has to allocated first.
   179      * be returned. Buffer for aFileName has to allocated first.
   154      */
   180      */
   155     void GetMediaFileNameL( TInt aObjectId, TPtr& aFileName );
   181     void GetMediaFileNameL( TInt aObjectId, TPtr& aFileName );
   156 
   182 
   157     /**
   183     /**
   158      * Find a folder shared from DB (ContentDirectory).
   184      * Find a folder shared from DB (ContentDirectory).
       
   185      * 
   159      * @param aUrlPath Name of URL path that needs to be found and converted
   186      * @param aUrlPath Name of URL path that needs to be found and converted
   160      * to aFolderPath
   187      * to aFolderPath
   161      * @param aFileName Name of shared file (can be null if just folder is looking for).
   188      * @param aFileName Name of shared file (can be null if just folder is 
       
   189      * looking for).
   162      * @param aSystemPath Name of shared folder.
   190      * @param aSystemPath Name of shared folder.
   163      * @return KErrNone or another of the system error codes.
   191      * @return KErrNone or another of the system error codes.
   164      */
   192      */
   165     TInt FindSharedFolderDBL(const TDesC8& aUrlPath, const TDesC8& aFileName,
   193     TInt FindSharedFolderDBL(const TDesC8& aUrlPath, const TDesC8& aFileName,
   166             HBufC8*& aSystemPath);
   194             HBufC8*& aSystemPath);
   173      */
   201      */
   174     TInt CheckImportUriL( TDesC8& aImportUri );
   202     TInt CheckImportUriL( TDesC8& aImportUri );
   175 
   203 
   176     /**
   204     /**
   177      * Checks DLNA correlations for given message.
   205      * Checks DLNA correlations for given message.
   178      * @since Series60 2.6
   206      * 
   179      * @param aMessage message for which correlations check will be performed 
   207      * @@param aTransaction http transaction.
   180      *  exists for given message.
       
   181      * @return KErrNone if no HTTPerror problem occurs	 
   208      * @return KErrNone if no HTTPerror problem occurs	 
   182      **/
   209      **/
   183     TInt CheckDLNACorrelationsL( CUpnpHttpFileServeTransaction& aTransaction );
   210     TInt CheckDLNACorrelationsL( 
       
   211     		CUpnpHttpDataServeTransaction& aTransaction );
   184 
   212 
   185 
   213 
   186     /**
   214     /**
   187      * Method returns content type of a resource
   215      * Method returns content type of a resource
   188      * @since Series60 3.2
   216      * 
   189      * @param aMessage, aMime, aFilename
   217      * @param aTransaction http transaction
       
   218      * @param aMime, content mimetype
       
   219      * @param aFilename , file name
   190      * @return KErrNone if mime type retrieved with no errors
   220      * @return KErrNone if mime type retrieved with no errors
   191      **/
   221      **/
   192     TInt GetContentTypeL( CUpnpHttpFileServeTransaction &aTransaction, HBufC8*& aMime,
   222     TInt GetContentTypeL( CUpnpHttpDataServeTransaction &aTransaction, 
       
   223     	HBufC8*& aMime,
   193         const TDesC16& aFilename );
   224         const TDesC16& aFilename );
   194  
   225  
   195 
   226     /**
       
   227       * Method returns content protocol info
       
   228       * 
       
   229       * @param aContentUri, content uri 
       
   230       * @return upnpdlnaprotocolinfo of the content.
       
   231       **/
   196     CUpnpDlnaProtocolInfo* ProtocolInfoL( const TDesC8& aContentUri );
   232     CUpnpDlnaProtocolInfo* ProtocolInfoL( const TDesC8& aContentUri );
   197 
   233 
       
   234     /**
       
   235       * Method adds header
       
   236       * 
       
   237       * @param aHeaderName, header name
       
   238       * @param aTransaction http transaction
       
   239       **/
   198     void AddHeaderIfNotEmptyL( const TDesC8& aHeaderName, 
   240     void AddHeaderIfNotEmptyL( const TDesC8& aHeaderName, 
   199         CUpnpHttpFileServeTransaction& aTransaction );
   241         CUpnpHttpDataServeTransaction& aTransaction );
   200     
   242     
   201     
   243     /**
       
   244       * Method returns unique filename
       
   245       * 
       
   246       * @param aFilename , file name
       
   247       * @param aFs , session to fileserver.
       
   248       * @return unique filename.ownership transferred
       
   249       **/    
   202     HBufC* MakeFileNameUniqueL( const TDesC& aFilename, RFs& aFs );
   250     HBufC* MakeFileNameUniqueL( const TDesC& aFilename, RFs& aFs );
   203 
   251 
   204     HBufC* PreparePostfixToMakeFileUniqueL( const TDesC& aFilename, RFs& aFs );
   252     /**
   205     
   253       * Method returns postfix string to make filename unique
       
   254       * 
       
   255       * @param aFilename , file name
       
   256       * @param aFs , session to fileserver.
       
   257       * @returns postfix string.ownership transferred
       
   258       **/
       
   259     HBufC* PreparePostfixToMakeFileUniqueL( const TDesC& aFilename, 
       
   260     		RFs& aFs );
       
   261 
       
   262     /**
       
   263       * Method returns filename
       
   264       * 
       
   265       * @param aFilename , file name
       
   266       * @param aFs , session to fileserver.
       
   267       * @returns filename string. ownership transferred
       
   268       **/
   206     HBufC* PrepareBaseFileNameL( const TDesC& aFilename, RFs& aFs );
   269     HBufC* PrepareBaseFileNameL( const TDesC& aFilename, RFs& aFs );
   207     
   270 
   208     TInt CheckCorelationL( CUpnpHttpFileServeTransaction& aTransaction,
   271     /**
       
   272       * Method verifies dlna correlation 
       
   273       * 
       
   274       * @param aTransaction http transaction
       
   275       * @returns dlna specific error codes 
       
   276       **/
       
   277     TInt CheckCorelationL( CUpnpHttpDataServeTransaction& aTransaction,
   209                             TUpnpDlnaCorelation& aDlnaCorelation );
   278                             TUpnpDlnaCorelation& aDlnaCorelation );
   210                             
   279     
   211     TInt CheckTransferModeL( CUpnpHttpFileServeTransaction& aTransaction,
   280     /**
       
   281       * Method verifies transfer modes
       
   282       * 
       
   283       * @param aTransaction http transaction
       
   284       * @returns dlna specific error codes
       
   285       **/                            
       
   286     TInt CheckTransferModeL( CUpnpHttpDataServeTransaction& aTransaction,
   212                              TUpnpDlnaCorelation& aDlnaCorelation );
   287                              TUpnpDlnaCorelation& aDlnaCorelation );
   213                              
   288                              
   214     TInt AppendCorelationHeadersL( CUpnpHttpFileServeTransaction& aTransaction,
   289     /**
   215                              TUpnpDlnaCorelation& aDlnaCorelation, TDesC8& aTransferMode  );
   290       * Method adds correlation headers
       
   291       * 
       
   292       * @param aTransaction http transaction
       
   293       * @param aDlnaCorelation, dlna correlation structure
       
   294       * @return KErrNone if successful
       
   295       **/
       
   296     TInt AppendCorelationHeadersL( 
       
   297     		CUpnpHttpDataServeTransaction& aTransaction,
       
   298             TUpnpDlnaCorelation& aDlnaCorelation, TDesC8& aTransferMode  );
       
   299     
       
   300     /**
       
   301       * Method returns decode content uri.
       
   302 	  *
       
   303       * @param contentURI, content uri
       
   304       * @return decoded content uri string 
       
   305       * ownership transferred.
       
   306       **/
       
   307     HBufC8* DecodeContentUriLC( const TPtrC8& contentURI);
   216 	
   308 	
   217 protected:	
   309 protected:	
   218 	
   310 	
   219     // Pointer to ContentDirectoryDataFinder implementation.
   311     // Pointer to ContentDirectoryDataFinder implementation.
   220     // Not owned.
   312     // Not owned.