remotestoragefw/webdavaccessplugin/inc/rsfwdavsession.h
branchRCL_3
changeset 15 88ee4cf65e19
parent 12 87c71b25c937
child 16 1aa8c82cb4cb
equal deleted inserted replaced
12:87c71b25c937 15:88ee4cf65e19
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  WebDAV session
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CRSFWDAVSESSION_H
       
    20 #define CRSFWDAVSESSION_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <http/mhttpauthenticationcallback.h>
       
    24 #include <xml/parser.h>
       
    25 #include "rsfwdavdefs.h"
       
    26 
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class CRsfwDavTransaction;
       
    30 class CRsfwDavFileInfo;
       
    31 class CRsfwPropFindParser;
       
    32 class CRsfwConnectionManager;
       
    33 class MRsfwDavResponseObserver;
       
    34 class MRsfwConnectionObserver;
       
    35 class CRsfwLockQueryParser;
       
    36 class CRsfwDirEnt;
       
    37 
       
    38 // CLASS DECLARATION
       
    39 /**
       
    40  *  Response handler for WebDAV requests
       
    41  *
       
    42  *  @lib davaccess.lib
       
    43  *  @since Series 60 3.1
       
    44  */
       
    45 class MRsfwDavResponseObserver
       
    46     {
       
    47 public:
       
    48     /**
       
    49      * Receive a notification of a completed request.
       
    50      * @param aWebDavTransactionId id of the request.
       
    51      */    
       
    52     virtual void RequestCompleteL(TUint aWebDavTransactionId) = 0;
       
    53 
       
    54     /**
       
    55      * Receive a notification of a failed request.
       
    56      * @param aWebDavTransactionId id of the request.
       
    57      */    
       
    58     virtual void RequestError(TUint aWebDavTransactionId, TInt aStatus) = 0;
       
    59     };
       
    60 
       
    61 
       
    62 // CLASS DECLARATION
       
    63 /**
       
    64  *  WebDAV session
       
    65  *
       
    66  *  Class created for the interface to  webdav client library
       
    67  *  Designed to encapsulate http,xml stuff
       
    68  *  Intended for communicating with one server at a time !
       
    69  * 
       
    70  *  Uses http transport framework: can do SSL, Basic + Digest Auth
       
    71  *  Uses symbian xmllib library for parsing
       
    72  *
       
    73  *  @lib davaccess.lib
       
    74  *  @since Series 60 3.1
       
    75  */
       
    76 class CRsfwDavSession: public CBase,
       
    77                       public MHTTPAuthenticationCallback
       
    78     {
       
    79 public: // Constructors and destructor
       
    80     /**
       
    81      * Two-phased constructor.
       
    82      */
       
    83     static CRsfwDavSession*
       
    84     CRsfwDavSession::NewL(MRsfwDavResponseObserver* aWebDavResponseObserver,
       
    85                          MRsfwConnectionObserver* aRsfwConnectionObserver);
       
    86     /**
       
    87      * Destructor.
       
    88      */
       
    89     virtual ~CRsfwDavSession();
       
    90 
       
    91 public: // New functions
       
    92     /**
       
    93        @function OpenL
       
    94        @discussion Opens the HTTP session and
       
    95          sets up parameters for the session
       
    96        @param aHost The full URI of the server
       
    97        including the path to the root directory
       
    98        @param aPort The port to connect to there
       
    99        @param aUserName  UserName to be used in Http basic or digest auth there
       
   100        @param aPassword  Password to be used in Http basic or digest auth there
       
   101        @param aAuxData Auxiliary information used for IAP selection
       
   102     */
       
   103     void OpenL(const TDesC& aHost,
       
   104                TInt aPort,
       
   105                const TDesC& aUserName,
       
   106                const TDesC& aPassword,
       
   107                const TDesC& aAuxData);
       
   108     
       
   109     /**
       
   110        @function OptionsL
       
   111        @discussion Runs an OPTIONS command to the passed uri to see if its
       
   112        available and force the authentication to run
       
   113        @return nothing
       
   114     */
       
   115     CRsfwDavTransaction* OptionsL();
       
   116     
       
   117     /**
       
   118        @function PropFindL
       
   119        @discussion Runs a PROPFIND command against the current server.
       
   120        Tells the server to only look for name, size related properties
       
   121        @param aPath The path relative to the root which should be used
       
   122        @param aIsDir Indicates whether the path points to a directory or a file
       
   123        @param aDirEnts Directory entry array to be filled
       
   124        @return pointer to the submitted WebDAV transaction
       
   125     */
       
   126     CRsfwDavTransaction* PropFindL(const TDesC& aPath,
       
   127                                   TInt aDepth,
       
   128                                   TBool aIsDir,
       
   129                                   RPointerArray<CRsfwDirEnt>& aDirEnts);
       
   130 
       
   131     /**
       
   132        @function GetL
       
   133        @discussion Runs GET command against the server
       
   134        @param aSrcPath The name of the resource to be fetched:
       
   135          expects this to be the path relative to the root directory
       
   136        @param aDstPath The path of the local file where the data is fetched
       
   137        @param aOffset offset from the start of the file
       
   138        @param aLength data length (can be NULL)
       
   139        @param aFlags operation options (see RemoteAccess.h)
       
   140        @return pointer to the submitted WebDAV transaction
       
   141     */
       
   142     // == GET
       
   143     CRsfwDavTransaction* GetL(const TDesC& aSrcPath,
       
   144                              const TDesC& aDstPath,
       
   145                              TInt aOffset,
       
   146                              TInt* aLength,
       
   147                              TUint aFlags);
       
   148 
       
   149     /**
       
   150        @function PutL
       
   151        @discussion Runs PUT command against the server
       
   152        @param aSrcPath The name of the resource to be copied:
       
   153        expects this to be an absolute path
       
   154        @param aDstPath The name of the resource to be created on the server:
       
   155        expected to be the path relative to the root directory
       
   156        @param aMimeType The MIME-type of the file 
       
   157        @param aOffset offset from the start of the file
       
   158        @param aLength data length (can be NULL)
       
   159        @param aTotalLength The total length, can be 0 if aLength is NULL or 0
       
   160        @param aUseContentRange Whether the server is assumed to support 
       
   161        Content-Range- header
       
   162        @param aLocktoken Possible lock token
       
   163        @return pointer to the submitted WebDAV transaction
       
   164     */
       
   165     // == PUT
       
   166     CRsfwDavTransaction* PutL(const TDesC& aSrcPath,
       
   167                              const TDesC& aDstPath,
       
   168                              const TDesC8& aMimeType,
       
   169                              TInt aOffset,
       
   170                              TInt aLength,
       
   171                              TInt aTotalLength,
       
   172                              TBool aUseContentRange,
       
   173                              const TDesC8* aLockToken = NULL);
       
   174 
       
   175     /**
       
   176        @function DeleteL
       
   177        @discussion Runs DELETE command against the server
       
   178        @param aResource The name of the resource to be deleted:
       
   179          expects this to be the path relative to the root directory
       
   180        @return pointer to the submitted WebDAV transaction
       
   181     */
       
   182     CRsfwDavTransaction* DeleteL(const TDesC& aPath, 
       
   183                                 TBool aDir,
       
   184                                 const TDesC8* aLockToken = NULL);
       
   185 
       
   186     /**
       
   187        @function MkDirL
       
   188        @discussion Runs MKCOL webdav command against the server
       
   189        @param aPath The name of the directory to be made:
       
   190        expects this to be the path relative to the root directory
       
   191        @return pointer to the submitted WebDAV transaction
       
   192     */
       
   193     CRsfwDavTransaction* MkDirL(const TDesC& aPath);   
       
   194 
       
   195     /**
       
   196        @function MoveL
       
   197        @discussion Runs MOVE command against the server
       
   198        @param aOldPath The name of the resource to be renamed:
       
   199        expects this to be the path relative to the root directory
       
   200        @param aNewPath The new name of the resource
       
   201        to be created on the server:
       
   202        expected to be the path relative to the root directory
       
   203        @param aOverwrite Specifies
       
   204        whether the server should overwrite a non-null destination resource 
       
   205        @return pointer to the submitted WebDAV transaction
       
   206     */
       
   207     CRsfwDavTransaction* MoveL(const TDesC& aOldPath,
       
   208                               const TDesC& aNewPath,
       
   209                               TBool aOverwrite,
       
   210                               const TDesC8* aSrcLockToken,
       
   211                               const TDesC8* aDstLockToken);
       
   212 
       
   213     /**
       
   214        @function LockL
       
   215        @discussion Runs LOCK command against the server
       
   216        @param aPath the resource to be locked:
       
   217        expects this to be the path relative to the root directory
       
   218        @param aFlags flags
       
   219        @param aTimeout lock timeout in seconds
       
   220        @param aDavFileInfo the location where collected file info should be set
       
   221        @return pointer to the submitted WebDAV transaction
       
   222     */
       
   223     CRsfwDavTransaction* LockL(const TDesC& aPath,
       
   224                               TUint aFlags,
       
   225                               TUint aTimeOut,
       
   226                               CRsfwDavFileInfo** aDavFileInfo);
       
   227 
       
   228     /**
       
   229        @function UnlockL
       
   230        @discussion Runs UNLOCK command against the server
       
   231        @param aPath the resource to be locked:
       
   232        expects this to be the path relative to the root directory
       
   233        @param aLockToken lock token
       
   234        @return pointer to the submitted WebDAV transaction
       
   235     */
       
   236     CRsfwDavTransaction* UnlockL(const TDesC& aPath,
       
   237                                 const TDesC8* aLockToken);
       
   238 
       
   239     /**
       
   240        @function RefreshLockL
       
   241        @discussion Refreshes a locked resource by using LOCK method
       
   242        @param aPath the resource to be locked:
       
   243        expects this to be the path relative to the root directory
       
   244        @param aTimeout lock timeout in seconds
       
   245        @param aLockToken lock token
       
   246        @param aDavFileInfo the location where collected file info should be set
       
   247        @return pointer to the submitted WebDAV transaction
       
   248     */
       
   249     CRsfwDavTransaction* RefreshLockL(const TDesC& aPath,
       
   250                                      TUint aTimeOut,
       
   251                                      const TDesC8* aLockToken,
       
   252                                      CRsfwDavFileInfo** aDavFileInfo);
       
   253 
       
   254     /**
       
   255        @function Error
       
   256        @return Most recently recieved error code
       
   257     */        
       
   258     TInt Error();
       
   259 
       
   260     /**
       
   261        @function ErrorMsg
       
   262        @return Most recently received error message from server
       
   263     */            
       
   264     const TDesC& ErrorMsg();
       
   265 
       
   266     RHTTPSession& HttpSession();
       
   267     void SetConnected(TBool aConnected);
       
   268     void SetWebDavSupportClass(TInt aWebDavSupportClass);
       
   269     TInt WebDavSupportClass();
       
   270     
       
   271     inline RFs& FileServerSession() {return iFs;};
       
   272     inline const TDesC& RootDirectory() {return iDavRoot;};
       
   273     void WebDavTransactionCompleteL(CRsfwDavTransaction* aWebDavTransaction);
       
   274     void WebDavTransactionError(CRsfwDavTransaction* aWebDavTransaction);
       
   275     void SetPropFindParametersL(RPointerArray<CRsfwDirEnt>* aDirEntArray,
       
   276                                const TDesC& aPropFindPath,
       
   277                                TInt aDepth);  
       
   278     void SetLockQueryParameters(CRsfwDavFileInfo* aDavFileInfo);
       
   279     void ParsePropFindResponseL(const TDesC8& aResponse);
       
   280     void ParseLockResponseL(const TDesC8& aResponse);
       
   281     void PropFindResponseEndL();
       
   282     void LockResponseEndL();  
       
   283     void CancelParsing(TWebDavOp aOp);                               
       
   284 
       
   285 public: // Functions from base classes
       
   286     // From MHTTPAuthenticationCallback
       
   287     TBool GetCredentialsL(const TUriC8& aURI,
       
   288                           RString aRealm, 
       
   289                           RStringF aAuthenticationType,
       
   290                           RString& aUserName, 
       
   291                           RString& aPassword);
       
   292 
       
   293 private:
       
   294     void ConstructL(MRsfwDavResponseObserver* aWebDavResponseObserver,
       
   295                     MRsfwConnectionObserver* aRsfwConnectionObserver);
       
   296     RStringPool StringPool();
       
   297     void Slashify(TDes& aStr);
       
   298     HBufC* BuildPathLC(const TDesC& aRoot,
       
   299                        const TDesC& aPath,
       
   300                        TBool aEndSlash);
       
   301     HBufC* BuildFullPathLC(const TDesC& aPath, TBool aEndSlash);
       
   302     HBufC8* BuildUriLC(const TDesC& aPath,
       
   303                        TBool aEndSlash,
       
   304                        TUriParser8* aUriParser);
       
   305     void SetHeaderL(RHTTPHeaders aHeaders,
       
   306                     TInt aHdrField,
       
   307                     const TDesC8& aHdrValue);
       
   308     void SetHeaderL(RHTTPHeaders aHeaders,
       
   309                     const TDesC8& aHdrName,
       
   310                     const TDesC8& aHdrValue);
       
   311     void SetBasicHeadersL(RHTTPHeaders aHeaders, 
       
   312                           const TUriC8& aUri,
       
   313                           TBool aNoProxy);
       
   314     void SetDepthHeaderL(RHTTPHeaders aHeaders, TInt aDepth);
       
   315     void SetLockTokenHeaderL(RHTTPHeaders aHeaders, 
       
   316                              const TDesC8* aUri, 
       
   317                              const TDesC8* aLockToken,
       
   318                              TBool aUseTaggedLockToken);
       
   319     TBool IsConnected();
       
   320     TUint NextWebDavTransactionId();
       
   321     HBufC8* EncodeL(const TDesC& aData);
       
   322     void SetupConnectionL();
       
   323  
       
   324 private: // Data
       
   325     // information about the connection
       
   326     HBufC8*  iUserName; 
       
   327     HBufC8*  iPassword;
       
   328     TBuf<KMaxServerNameLen>  iHost;
       
   329     TBuf<KMaxPath>           iDavRoot;
       
   330     TBuf<KMaxPath>           iHostRoot;
       
   331     TBuf<KMaxConnParameter>  iAuxData;
       
   332     HBufC8*                  iEncodedHost; // UTF8-encoded host name part
       
   333 
       
   334     MRsfwDavResponseObserver* iWebDavResponseObserver;
       
   335     MRsfwConnectionObserver* iRsfwConnectionObserver;
       
   336     
       
   337     CRsfwPropFindParser*         iPropFindParserImpl;
       
   338     CRsfwLockQueryParser*        iLockQueryParserImpl;
       
   339     Xml::CParser*            iPropFindParser;
       
   340     Xml::CParser*            iLockQueryParser;
       
   341     
       
   342     // whether XML parser should be cancelled if the transaction is cancelled
       
   343     TBool                   iPropfindParsingActive; 
       
   344                                    
       
   345 
       
   346     TBool        iConnected;    // whether we have a successful TCP session
       
   347     RFs          iFs;
       
   348     TInt         iWebDavSupportClass;
       
   349     TInt         iCredentialRequestCount;
       
   350     TUint        iCurrentWebDavTransactionId;
       
   351     RHTTPSession iHttpSession;
       
   352     CRsfwConnectionManager* iRsfwConnectionManager;
       
   353     };
       
   354 
       
   355 #endif // CRSFWDAVSESSION_H
       
   356 
       
   357 // End of File