browserutilities/feedsengine/FeedsServer/UrlHandler/inc/HttpHandler.h
changeset 0 dd21522fd290
child 36 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 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 the License "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:  A class that fetches resources via HTTP 1.1.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef HTTP_HANDLER_H
       
    20 #define HTTP_HANDLER_H
       
    21 
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <http/mhttptransactioncallback.h>
       
    26 #include <http/rhttpheaders.h>
       
    27 #include <http/rhttptransaction.h>
       
    28 
       
    29 #include "HttpConnection.h"
       
    30 #include "LeakTracker.h"
       
    31 #include "UrlHandler.h"
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // MACROS
       
    36 
       
    37 // DATA TYPES
       
    38 
       
    39 // FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 class CTimer;
       
    43 class RHTTPSession;
       
    44 class RStringPool;
       
    45 
       
    46 // CLASS DECLARATION
       
    47 
       
    48 
       
    49 /**
       
    50 *  A class that fetches resources via HTTP 1.1.
       
    51 *
       
    52 *  \b Library: FeedsEngine.lib
       
    53 *
       
    54 *  @since 3.0
       
    55 */
       
    56 class CHttpHandler: public CUrlHandler, public MHttpConnectionObserver,
       
    57         public MHTTPTransactionCallback
       
    58     {
       
    59     public:  // Constructors and destructor
       
    60         /**
       
    61         * Two-phased constructor.
       
    62         */
       
    63         static CHttpHandler* NewL(CHttpConnection& aHttpConnection);
       
    64         
       
    65         /**
       
    66         * Destructor.
       
    67         */        
       
    68         virtual ~CHttpHandler();
       
    69         
       
    70         
       
    71     public:  // From CUrlHandler
       
    72         /**
       
    73         * Loads the given url -- asynchronously
       
    74         *
       
    75         * @since 3.0
       
    76         * @param aUrl The url to load
       
    77         * @param aObserver The load observer.
       
    78         * @return void.
       
    79         */
       
    80         virtual void LoadUrlL(const TDesC& aUrl, MLoadObserver& aObserver);
       
    81         
       
    82 
       
    83       public:  // From MHttpConnectionObserver
       
    84         /**
       
    85         * Notifies the observer that the connection is available.
       
    86         * 
       
    87         * @since 3.0
       
    88         * @return 
       
    89         */
       
    90         virtual void ConnectionAvailable(); 
       
    91         
       
    92         /**
       
    93         * Notifies the observer that the establishment of the connection failed.
       
    94         * 
       
    95         * @since 3.0
       
    96         * @param aStatus The reason for the failure.
       
    97         * @return 
       
    98         */
       
    99         virtual void ConnectionFailed(TInt aStatus); 
       
   100 
       
   101 
       
   102 	  public: // From MHTTPTransactionCallback
       
   103         /**
       
   104         * Called when the filter's registration conditions are satisfied for events that
       
   105         * occur on a transaction.
       
   106         *
       
   107         * @since 3.0
       
   108         * @param aTransaction The transaction that the event has occurred on.
       
   109         * @param aEvent The event that has occurred.
       
   110         * @return void.
       
   111         */
       
   112         virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
       
   113 
       
   114         /**
       
   115         * Called when RunL leaves from a transaction event. This works in the same
       
   116         * way as CActve::RunError; return KErrNone if you have handled the error.
       
   117         *
       
   118         * @since 3.0
       
   119         * @param aError The leave code that RunL left with.
       
   120         * @param aTransaction The transaction that was being processed.
       
   121         * @param aEvent The Event that was being processed.
       
   122         * @return KErrNone if the error has been cancelled or the code
       
   123         *         of the continuing error otherwise.
       
   124         */
       
   125         virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, 
       
   126                 const THTTPEvent& aEvent);
       
   127         
       
   128 
       
   129     private:
       
   130         /**
       
   131         * C++ default constructor.
       
   132         */
       
   133         CHttpHandler(CHttpConnection& aHttpConnection);
       
   134         
       
   135         /**
       
   136         * By default Symbian 2nd phase constructor is private.
       
   137         */
       
   138         void ConstructL();
       
   139 
       
   140         /**
       
   141         * Cleanup stack callback method to release a DataSupplier.
       
   142         *
       
   143         * @since 3.0
       
   144         * @param aPtr A libxml2 document ptr.
       
   145         * @return void.
       
   146         */
       
   147         static void CleanupDataSupplier(TAny *aPtr);
       
   148 
       
   149         /**
       
   150         * Get the content-type and char-encoding from the response header.
       
   151         *
       
   152         * @since 3.0
       
   153         * @param aContentType The content-type.
       
   154         * @param aCharSet The char-encoding.
       
   155         * @return void.
       
   156         */       
       
   157         void GetContentTypeL(TDesC*& aContentType, TDesC*& aCharSet);
       
   158 
       
   159         /**
       
   160         * Passes the status code and responseBody to the observer.  The observer
       
   161         * adopts aResponseBody.
       
   162         *
       
   163         * @since 3.0
       
   164         * @param aStatusCode The status code - normalized to the http response codes.
       
   165         * @param aResponseBody The response body or NULL.
       
   166         * @param aContentType The content-type.
       
   167         * @param aCharSet The char-encoding.
       
   168         * @return void.
       
   169         */
       
   170         void LoadCompleted(TInt aStatusCode, TDesC8* aResponseBody,
       
   171                 const TDesC& aContentType, const TDesC& aCharSet);
       
   172 
       
   173         /**
       
   174         * The timer's callback used to abort connections that stop responding.
       
   175         *
       
   176         * @since 3.0
       
   177         * @param aPtr Holds the iTimerState pointer.
       
   178         * @return An error code.
       
   179         */       
       
   180         static TInt TimerCallback(TAny* aPtr);
       
   181 
       
   182 
       
   183     private:
       
   184         const TTimeIntervalMicroSeconds32 KTimerPeriod;
       
   185         
       
   186         TLeakTracker      iLeakTracker;
       
   187 
       
   188         CHttpConnection*  iHttpConnection;
       
   189         TBool             iIsConnectionObserver;
       
   190         RHTTPSession&     iSession;
       
   191         RStringPool       iStringPool;
       
   192         RHTTPTransaction  iTransaction;
       
   193         RHTTPHeaders      iRespHeaders;
       
   194         RHTTPHeaders	  iUserAgentHeader;
       
   195 
       
   196         MLoadObserver*    iObserver;
       
   197 
       
   198         HBufC8*           iResponseBuffer;
       
   199 
       
   200         CPeriodic*        iTimer;
       
   201         TCallBack         iTimerState;
       
   202         TTime             iLastActivity;
       
   203         TInt			  iStatusCode;
       
   204     };
       
   205 
       
   206 #endif      // HTTP_HANDLER_H
       
   207             
       
   208 // End of File