IMPSengine/ImpsDataChannel/inc/HttpTransportAdapter.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2003 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: Adapter for Http transport.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef HTTPTRANSPORTADAPTER_H
       
    21 #define HTTPTRANSPORTADAPTER_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <f32file.h>
       
    25 //HTTP Stack
       
    26 #include <http.h>
       
    27 //Bearer observer
       
    28 #include <msgbearerobscallback.h>
       
    29 //IMPS Sender interface
       
    30 #include "ImpsDataChannelAPI.h"
       
    31 //Internal headers
       
    32 #include "ImpsTransportTimer.h"
       
    33 
       
    34 //COMMON CONSTANTS
       
    35 _LIT( KLogDir,                      "ImpsDataChannel" );
       
    36 _LIT( KTransportLogFile,            "ImpsDataChannel.txt" );
       
    37 const TInt KLogBufferMaxSize        = 2000;
       
    38 _LIT( KDateFormat,                  "%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3" );
       
    39 const TInt KMaxSubmitSize           = 1024;
       
    40 const TInt KMaxHeaderNameLen        = 32;
       
    41 const TInt KMaxHeaderValueLen       = 128;
       
    42 const TInt KBufferMaxSize           = 2048;
       
    43 
       
    44 
       
    45 
       
    46 //FORWARD DECLARATIONs
       
    47 class CImpsHttpTransaction;
       
    48 class MImpsReceiver;
       
    49 
       
    50 // CLASS DECLARATION
       
    51 class CHttpTransportAdapter : public CBase,
       
    52             public MImpsSender,
       
    53             public MMsgBearerObsCallback,
       
    54             public MHTTPTransactionCallback,
       
    55             public MImpsTransportTimerCallback
       
    56     {
       
    57     public:  // Constructors and destructor
       
    58 
       
    59         /**
       
    60         * Symbian OS default constructor.
       
    61         * @param aSession A reference to an opened file session
       
    62         * @param aMimeType MIME type of the messages to be sent
       
    63         * @param aReceiver The receiving object
       
    64         * @return CHttpTransportAdapter
       
    65         */
       
    66         static CHttpTransportAdapter* NewL( MImpsDataReceiver& aReceiver,
       
    67                                             MMsgConnManager& aConnManager,
       
    68                                             const TDesC8& aMimeType );
       
    69 
       
    70         /**
       
    71         * Opens a connection to IMPS server
       
    72         * @param aId ID of the request
       
    73         * @param aLog Is logging enabled or not
       
    74         * @param aProxy Shall we connect through a proxy server?
       
    75         * @param aSAP The address of the remote host
       
    76         * @param aIAP The ID of the access point to use
       
    77         */
       
    78         virtual void OpenL( const TDesC& aSAP );
       
    79 
       
    80         /**
       
    81         * Closes connection to WV server.
       
    82         * @return TInt
       
    83         */
       
    84         virtual void Close();
       
    85 
       
    86         /**
       
    87         * Send one IMPS message.
       
    88         * @param aId Transaction ID
       
    89         * @param aMessage Message to be sent
       
    90         * @param aExpiryTime The time period after which the message expires
       
    91         */
       
    92         virtual void SendL( const TInt aId,
       
    93                             const TDesC8& aMessage,
       
    94                             const TInt aExpiryTime = 0 );
       
    95 
       
    96         /**
       
    97         * Cancel the sending of all pending requests.
       
    98         * Obviously, the transactions cannot be "sucked back",
       
    99         * but they can be closed so that the responses never
       
   100         * reach the client application
       
   101         */
       
   102         virtual void CancelAll();
       
   103 
       
   104         /**
       
   105         * Cancel the sending of a named transaction.
       
   106         * Obviously, the transaction cannot be "sucked back",
       
   107         * but it can be closed so that the response never
       
   108         * reaches the client application
       
   109         */
       
   110         virtual void CancelTransaction( const TInt aTID );
       
   111 
       
   112         /**
       
   113         * Return the number of pending requests.
       
   114         * @return TInt
       
   115         */
       
   116         inline virtual TInt PendingRequests() const;
       
   117 
       
   118         /**
       
   119         * Destructor, which makes the C++ destructor "visible" to users
       
   120         * of the MImpsSender interface. This function simply says "delete this".
       
   121         */
       
   122         inline virtual void Destroy();
       
   123 
       
   124         /**
       
   125         * Destructor.
       
   126         */
       
   127         virtual ~CHttpTransportAdapter();
       
   128 
       
   129     public:   //New functions
       
   130 
       
   131         /**
       
   132         * Returns the MIME type of the messages
       
   133         * @return TPtrC8 The MIME type of the messages
       
   134         */
       
   135         inline TPtrC8 MimeType() const;
       
   136 
       
   137         /**
       
   138         * Returns the address of the default SAP
       
   139         * @return TUriParser The default SAP
       
   140         */
       
   141         inline TUriParser8 DefaultSAP() const;
       
   142 
       
   143         /**
       
   144         * Returns a reference to the currently active HTTP session
       
   145         * NOTE: Causes a panic if the session is closed.
       
   146         * @return RHTTPSession The currently active HTTP session
       
   147         */
       
   148         inline RHTTPSession& HttpSession();
       
   149 
       
   150         /**
       
   151         * Returns a reference to the receiver object
       
   152         * @return MImpsDataReceiver The current data receiver
       
   153         */
       
   154         inline MImpsDataReceiver& ReceiverHandle() const;
       
   155 
       
   156         /**
       
   157         * Check whether the HTTP session has been closed
       
   158         * @return TBool
       
   159         */
       
   160         inline TBool SessionClosed() const;
       
   161 
       
   162 #ifdef _DEBUG
       
   163 
       
   164         /**
       
   165         * A global logging function for 16 bit data.
       
   166         * @param aCommand command to be handled
       
   167         */
       
   168         static void WriteToLog( TRefByValue<const TDesC> aFmt, ... );
       
   169 
       
   170         /**
       
   171         * A global logging function for 8 bit data.
       
   172         * @param aCommand command to be handled
       
   173         */
       
   174         static void WriteToLog( TRefByValue<const TDesC8> aFmt, ... );
       
   175 
       
   176 #endif
       
   177 
       
   178     private:
       
   179 
       
   180         /**
       
   181         * C++ default constructor.
       
   182         */
       
   183         CHttpTransportAdapter( MImpsDataReceiver& aReceiver,
       
   184                                MMsgConnManager& aConnManager );
       
   185 
       
   186         /**
       
   187         * Symbian OS default constructor.
       
   188         * @param aMimeType MIME type of the messages
       
   189         */
       
   190         void ConstructL( const TDesC8& aMimeType );
       
   191 
       
   192         /**
       
   193         * Initialises an HTTP session
       
   194         */
       
   195         void InitialiseSessionL();
       
   196 
       
   197         /**
       
   198         * Writes data to the input buffer
       
   199         * @param TDesC8& aBodyData
       
   200         */
       
   201         void WriteDataToInputBufferL( const TDesC8& aBodyData );
       
   202 
       
   203         /**
       
   204         * Stores the address of the proxy currently in use
       
   205         * @param aProxy Address of the HTTP proxy server
       
   206         */
       
   207         void SetProxyL();
       
   208 
       
   209         /**
       
   210         * Stores the address of the proxy currently in use
       
   211         * @param aProxy Address of the HTTP proxy server
       
   212         */
       
   213         void HandleBearerEventL( TBool aIsAuthClose, TMsgBearerEvent aBearerEvent );
       
   214 
       
   215         /**
       
   216         * Stores the address of the proxy currently in use
       
   217         * @param aProxy Address of the HTTP proxy server
       
   218         */
       
   219         void HandleTemporaryRedirectionL( RHTTPTransaction aTransaction );
       
   220 
       
   221         /**
       
   222         * Stores the address of the proxy currently in use
       
   223         * @param aProxy Address of the HTTP proxy server
       
   224         */
       
   225         void HandlePermanentRedirectionL( RHTTPTransaction aTransaction );
       
   226 
       
   227         /**
       
   228         * Stores the address of the SAP currently in use
       
   229         * @param aURL Address of the remote host
       
   230         */
       
   231         void SetUrlL( const TDesC& aURL );
       
   232 
       
   233         /**
       
   234         * Sets the MIME type of the messages
       
   235         * @param aMimeType MIME type of the messages
       
   236         */
       
   237         void SetMimeTypeL( const TDesC8& aMimeType );
       
   238 
       
   239         /**
       
   240         * Map an HTTP request to the corresponding IMPS request
       
   241         * @param aTransaction HTTP Transaction
       
   242         * @return CImpsHttpTransaction
       
   243         */
       
   244         CImpsHttpTransaction* ImpsTransaction( const RHTTPTransaction& aTransaction );
       
   245 
       
   246         /**
       
   247         * Returns the Content-Length header, if specified
       
   248         * @param aResponse HTTP response
       
   249         * @return TInt
       
   250         */
       
   251         TInt ContentLengthL( RHTTPResponse aResponse ) const;
       
   252 
       
   253         /**
       
   254         * Returns the Content-Length header, if specified
       
   255         * @param aResponse HTTP response
       
   256         * @return TInt
       
   257         */
       
   258         TPtrC8 LocationL( RHTTPResponse aResponse ) const;
       
   259 
       
   260         /**
       
   261         * Convert undefined HTTP stack errors into
       
   262         * something a but more meaningful
       
   263         * @param const TInt aError
       
   264         * @return TInt
       
   265         */
       
   266         TInt ConvertUndefinedError( const TInt aError );
       
   267 
       
   268         /**
       
   269         * Remove the named transaction from the queue of pending requests.
       
   270         * @param aRemove The transaction to be removed
       
   271         */
       
   272         void RemoveFromQueue( const CImpsHttpTransaction* aRemove );
       
   273 
       
   274 #ifdef _DEBUG
       
   275 
       
   276         /**
       
   277         * Write response headers to the log file
       
   278         * @param aTrans HTTP Transaction
       
   279         */
       
   280         void DumpResponseHeadersL( RHTTPTransaction& aTrans,
       
   281                                    const TInt aTransactionID );
       
   282 
       
   283         /**
       
   284         * Remove the log file from a previous session
       
   285         */
       
   286         void DeleteLogFilesL();
       
   287 
       
   288 #endif
       
   289 
       
   290         /**
       
   291         * From MHTTPTransactionCallback, handles all responses
       
   292         * coming from the remote host
       
   293         * @param aTransaction The finished transaction
       
   294         * @param aEvent Type of the event
       
   295         */
       
   296         void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   297 
       
   298         /**
       
   299         * From MHTTPTransactionCallback, called when the RunL() of a transaction leaves
       
   300         * @param aInt The error the HTTP framework left with
       
   301         * @param aTransaction The failed transaction
       
   302         * @param aEvent The event that was being processed
       
   303         * @return KErrNone (HTTP framework panics if client returns any other error)
       
   304         */
       
   305         TInt MHFRunError( TInt aInt, RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   306 
       
   307         /**
       
   308         * Handles timer expiry event
       
   309         * @param aRequester The object that started the timer
       
   310         * @param aStatus Status of the timer object
       
   311         */
       
   312         void HandleTransportTimerEventL( TImpsTimingRequester* aRequester,
       
   313                                          TInt aStatus );
       
   314 
       
   315     private: //Data
       
   316 
       
   317         TBool                                       iConnected;
       
   318         TBool                                       iSuspend;
       
   319         TBool                                       iSessionClosed;
       
   320         RHTTPSession                                iHttpSession;
       
   321         RPointerArray<CImpsHttpTransaction>         iTransactionQueue;
       
   322         TUriParser8                                 iDefaultURL;
       
   323         MImpsDataReceiver&                          iReceiver;
       
   324         MMsgConnManager&                            iConnManager;
       
   325         MHTTPDataSupplier*                          iRespBody;
       
   326         CBufBase*                                   iResponseBuffer;
       
   327         HBufC8*                                     iProxyBuffer;
       
   328         HBufC8*                                     iUrlBuffer;
       
   329         HBufC8*                                     iMimeBuffer;
       
   330         TInt                                        iCurrentDataLength;
       
   331     };
       
   332 
       
   333 #include "HttpTransportAdapter.inl"
       
   334 
       
   335 #endif
       
   336 
       
   337 // End of File