wmdrm/camese/wmdrmdladefaulthttpplugin/inc/wmdrmdladefaulthttpmanager.h
changeset 0 95b198f216e5
child 1 c562c0bc23e5
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:  Defines the CWmDrmDlaDefaultHttpManager class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef WMDRMDLADEFAULTHTTPMANAGER_H
       
    20 #define WMDRMDLADEFAULTHTTPMANAGER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <es_sock.h>
       
    26 #include <es_enum.h>
       
    27 #include <in_sock.h>
       
    28 
       
    29 #include <http/mhttpauthenticationcallback.h>
       
    30 #include <http/mhttptransactioncallback.h>
       
    31 #include <http/mhttpdatasupplier.h>
       
    32 
       
    33 #include <commdbconnpref.h>     // TCommDbConnPref (since 7.0s)
       
    34 
       
    35 #include "wmdrmdladefaulthttpmanagerobserver.h"
       
    36 
       
    37 /**
       
    38 * CWmDrmDlaDefaultHttpManager
       
    39 * The HTTP communication handling class
       
    40 */
       
    41 NONSHARABLE_CLASS( CWmDrmDlaDefaultHttpManager ) :
       
    42     public CActive,
       
    43     public MHTTPTransactionCallback,
       
    44     public MHTTPAuthenticationCallback
       
    45     {
       
    46     public:
       
    47         /**
       
    48          * THeader - encapsulates an HTTP header id and its value.
       
    49          */
       
    50         struct THeader
       
    51             {
       
    52         public:
       
    53             inline THeader( TInt aField, const TDesC8& aDesC ) : 
       
    54                 iField(aField), iVal(aDesC) {};
       
    55         public:
       
    56             TInt iField;            // e.g. 'HTTP::EAccept'
       
    57             const TDesC8& iVal;     // value: e.g. '*/*'
       
    58             };
       
    59 
       
    60     public:
       
    61         /**
       
    62          * Constructor.
       
    63          * @param aObserver - reference to observer
       
    64          * @return address of an instance of this class
       
    65          */
       
    66         static CWmDrmDlaDefaultHttpManager* NewL( 
       
    67                     MWmDrmDlaDefaltHttpManagerObserver& aObserver );
       
    68 
       
    69         /**
       
    70          * Constructor.
       
    71          * @param aObserver - reference to observer
       
    72          * @param aIapNumber - Internet Access Point to be used
       
    73          * @return address of an instance of this class
       
    74          */
       
    75         static CWmDrmDlaDefaultHttpManager* NewL( 
       
    76                     MWmDrmDlaDefaltHttpManagerObserver& aObserver,
       
    77                     TUint32 aIapNumber );
       
    78 
       
    79         /**
       
    80          * Destructor.
       
    81          */
       
    82         virtual ~CWmDrmDlaDefaultHttpManager();
       
    83 
       
    84         /**
       
    85          * Called to start the GET transaction using the configured IAP.
       
    86          * @param aUrl - URL to be used for the transaction
       
    87          * @param aHeaders - a list of headers and their values to be 
       
    88          *                   included with the HTTP request
       
    89          */
       
    90         void Get( const TDesC8& aUrl, const RArray<THeader>& aHeaders );
       
    91 
       
    92         /**
       
    93          * Called to start the POST transaction using the configured IAP.
       
    94          * @param aUrl - URL to be used for the transaction
       
    95          * @param aHeaders - a list of headers and their values to be 
       
    96          *                   included with the HTTP request
       
    97          * @param aDataSupplier - interface to be used to get the POST data
       
    98          */
       
    99         void Post( const TDesC8& aUrl, const RArray<THeader>& aHeaders, 
       
   100                    MHTTPDataSupplier* aDataSupplier );
       
   101 
       
   102         /**
       
   103          * To be called to stop an ongoing transaction instead of Cancel.
       
   104          * Cancel SHOULD NOT BE CALLED by clients.
       
   105          */
       
   106         void Stop();
       
   107 
       
   108         /**
       
   109         * Notifies the CWmDrmDlaDefaultHttpManager that another piece of data
       
   110         * is available to be sent as the body of a request.
       
   111         * If the MHTTPDataSupplier::NextDataPart returns EFalse indicating
       
   112         * there is more data available this method needs to be called for the
       
   113         * next piece of data to be requested from the MHTTPDataSupplier.
       
   114         * @leave any of the system wide error codes.
       
   115         */
       
   116         void MoreDataAvailableL();
       
   117 
       
   118         /**
       
   119          * If set to true, the connection is not closed when a
       
   120          * transaction ends but when the object is deleted. Default: false.
       
   121          * @param aKeepAlive - value of the KeepAlive property
       
   122          */
       
   123         void SetKeepAlive( TBool aKeepAlive );
       
   124 
       
   125         /**
       
   126          * Retrieves the value of the KeepAlive property
       
   127          */
       
   128         TBool KeepAlive() const;
       
   129 
       
   130         /**
       
   131          * Retrieves the current connection info.
       
   132          * This method leaves with KErrNotReady if a connection
       
   133          * is not open.
       
   134          */
       
   135         void GetConnectionInfoL( TConnectionInfo& aConnectionInfo );
       
   136 
       
   137         /**
       
   138          * Set the IAP connection for the next Get or Post
       
   139          * @param aIapId The IAP connection that will be used
       
   140          */
       
   141         void SetIapId( TInt aIapId );
       
   142         
       
   143         /**
       
   144          * Get the IAP Connection ID
       
   145          */
       
   146         TInt IapId();
       
   147 
       
   148     private: // From MHTTPTransactionCallback
       
   149         
       
   150         virtual void MHFRunL( RHTTPTransaction aTransaction, 
       
   151                               const THTTPEvent& aEvent );
       
   152         virtual TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, 
       
   153                                   const THTTPEvent& aEvent );
       
   154 
       
   155     private: // From MHTTPAuthenticationCallback
       
   156         
       
   157         virtual TBool GetCredentialsL( const TUriC8& aURI, RString aRealm, 
       
   158                                        RStringF aAuthenticationType,
       
   159                                        RString& aUsername, 
       
   160                                        RString& aPassword );
       
   161 
       
   162     private:    // From CActive
       
   163         
       
   164         void DoCancel();
       
   165         void RunL();
       
   166         TInt RunError(TInt aError);
       
   167 
       
   168     private:
       
   169         
       
   170         /**
       
   171          * Contructor
       
   172          * @param aObserver An observer to monitor the HTTP communications
       
   173          * @param aIap An IAP connection to use for HTTP communication
       
   174          */
       
   175         CWmDrmDlaDefaultHttpManager( 
       
   176                 MWmDrmDlaDefaltHttpManagerObserver& aObserver, 
       
   177                 TUint32 aIapNumber );
       
   178 
       
   179         /**
       
   180          * Symbian OS 2nd phase constructor.
       
   181          */
       
   182         void ConstructL();
       
   183 
       
   184     private:
       
   185         
       
   186         // State transition handlers
       
   187         /**
       
   188          * Handler for the EStart state.
       
   189          */
       
   190         void InitializeL();
       
   191         /**
       
   192          * Handler for the EInitialize state.
       
   193          */
       
   194         void Open();
       
   195         /**
       
   196          * Handler for the EOpen state.
       
   197          */
       
   198         void SubmitL();
       
   199 
       
   200         // Utility methods
       
   201         void DoStartL( const TDesC8& aUrl, const RArray<THeader>& aHeaders );
       
   202         /**
       
   203          * Close HTTP connection and clean up instance variables.
       
   204          */
       
   205         void HandleDownloadComplete( TInt aError );
       
   206         /**
       
   207          * Close HTTP transaction and clean up instance variables.
       
   208          */
       
   209         void CleanupTransaction();
       
   210         /**
       
   211          * Close connection and clean up instance variables.
       
   212          */
       
   213         void CleanupConnection();
       
   214         /**
       
   215          * Complete itself to keep state machine running
       
   216          */
       
   217         void CompleteSelf();
       
   218         /**
       
   219          * Set the HTTP header to send
       
   220          */
       
   221         void SetHeaderL( RHTTPHeaders& aHeaders, TInt aHdrField, 
       
   222                          const TDesC8& aHdrValue ) const;
       
   223         /**
       
   224          * Delete the username and password used in authentication
       
   225          */
       
   226         void DeleteUsernamePassword();
       
   227 
       
   228     private:    // Private types
       
   229         
       
   230         // Asynchronous connection states
       
   231         enum TState
       
   232             {
       
   233             EConstructed,
       
   234             EStart,
       
   235             EInitialize,
       
   236             EOpen,
       
   237             ESubmit
       
   238             };
       
   239 
       
   240         // HTTP operation: GET or POST
       
   241         enum TOperation
       
   242             {
       
   243             EGet,
       
   244             EPost
       
   245             };
       
   246 
       
   247     private: // Data
       
   248         
       
   249         MWmDrmDlaDefaltHttpManagerObserver& iObserver;
       
   250 
       
   251         TState iState; // State of the asynch connection
       
   252         TInt iError;
       
   253         TBool iCredentialsOk;
       
   254 
       
   255         RSocketServ  iSocketServer;
       
   256         RConnection  iConnection;
       
   257         TCommDbConnPref iCommDbPrefs;
       
   258 
       
   259         TUint32 iIapNumber;
       
   260 
       
   261         RHTTPSession iHttpSession;
       
   262         RHTTPTransaction iHttpTransaction;
       
   263         MHTTPDataSupplier* iBody;
       
   264 
       
   265         TBool iTransactionOpen;
       
   266         TBool iInCallback;
       
   267 
       
   268         HBufC8* iSrcAddress;
       
   269         RArray<TInt> iHdrFields;
       
   270         RArray<HBufC8*> iHdrValues;
       
   271 
       
   272         HBufC8* iUsername;
       
   273         HBufC8* iPassword;
       
   274 
       
   275         TOperation iOperation;
       
   276         MHTTPDataSupplier* iDataSupplier;   // not owned
       
   277 
       
   278         TBool iKeepAlive;
       
   279     };
       
   280 
       
   281 #endif // WMDRMDLADEFAULTHTTPMANAGER_H
       
   282 
       
   283 // End of File
       
   284