hotspotfw/internetconnectivitytestservice/inc/ictshttphandler.h
author hgs
Thu, 27 May 2010 10:28:52 +0300
changeset 32 5bbf13e885a0
parent 0 56b72877c1cb
permissions -rw-r--r--
201021_1

/*
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:   Contains implementation for connectivity test with HTTP
*
*/



#ifndef ICTSHTTPHANDLER_H
#define ICTSHTTPHANDLER_H

#include <ecom/ecom.h>
#include <es_enum.h>
#include <http.h>

#include "ictscommon.h"

class CIctsEngine;

/**
 *  Handles HTTP related things.
 *
 *  Sends HTTP GET using HTTP FW. Returns results to the caller.
 *
 *  @lib ictsclientinterface.lib
 */
class CIctsHttpHandler : public CTimer, 
                         public MHTTPTransactionCallback
    {
    
    public:

        /**
        * Static constructor.
        */    
        static CIctsHttpHandler* NewL( CIctsEngine& aOwner,
                                        TInt aHttpResponseTime );
    
        /**
        * Destructor.
        */
        virtual ~CIctsHttpHandler();
    
        /**
        * Send HTTP GET request 
        *
        * @param aIPAddress IP address
        * @param aIapID IAP id
        * @param aNetworkId Network id
        * @return KErrNone if successful
        */
        TInt SendHttpRequestL( TDesC8& aIPAddress, 
                                 TUint32 aIapID, 
                                   TUint32 aNetworkId );
        
        /**
        * Cancels HTTP GET request 
        *
        * @return None
        */
        void CancelHttpRequestL();
    
    public: // from MHTTPTransactionCallback

        /**
        * Callback for HTTP FW to call when HTTP events occur
        *
        * @param aTransaction HTTP transaction
        * @param aEvent HTTP event
        * @return None
        */
        virtual void MHFRunL( RHTTPTransaction aTransaction, 
                                const THTTPEvent& aEvent);
    
        /**
        * Callback for HTTP FW to call when HTTP errors occur
        *
        * @param aError error code
        * @param aTransaction HTTP transaction
        * @param aEvent HTTP event
        * @return None
        */                        
        virtual TInt MHFRunError( TInt aError, 
                                    RHTTPTransaction aTransaction, 
                                      const THTTPEvent& aEvent);

    protected:  // Functions from base classes
        
        /**
        * From CActive Handles an active object's request completion event.
        */
        void RunL();
    
    private:
    
        /**
        * C++ default constructor.
        *
        * @param aOwner Owner of this instance
        * @param aHttpResponseTime Max time for response
        */
        CIctsHttpHandler( CIctsEngine& aOwner, TInt aHttpResponseTime );

        /**
        * By default Symbian 2nd phase constructor is private.
        */
        void ConstructL();
    
        /**
        * Set HTTP connection info 
        *
        * @param aConnection Network connection
        * @param aSocketServ Socket server
        * @return None
        */
        void SetHttpConnectionInfoL( RConnection& aConnection, 
                                       RSocketServ& aSocketServ );
        /**
        * Send HTTP request 
        *
        * @param aIp IP address
        * @return None
        */
        void SendHttpGetL( TDesC8& aIp ); 

        /**
        * Check http prefix in URL/IP address
        *
        * @param aIPAddress URL
        * @return ETrue if found, else EFalse
        */ 
        TBool CheckHttp( TDesC8& aIPAddress );

        /**
        * Checks if HTTP status code is a redirect (301,302,303,307)
        *
        * @param aTransaction HTTP transactionL
        * @return ETrue if found, else EFalse
        */
        TBool CheckStatusCodeL( RHTTPTransaction aTransaction );
    
    private: // data

        /**
        * Handle to HTTP session
        * Own.  
        */
        RHTTPSession iHttpSession;
    
        /**
        * Handle to HTTP transaction
        * Own.  
        */
        RHTTPTransaction iHttpTransaction;

        /**
        * Handle to socket server
        * Own.  
        */
        RSocketServ iSocketServ;
    
        /**
        * Handle to connection
        * Own.  
        */
        RConnection iConnection;
    
        /**
        * String from HTTP FW
        */
        TBuf< KHttpResponseLength > iString;
    
    
        /**
        * Reference of owner class
        * Not Own.  
        */
        CIctsEngine& iOwner;
    
        /**
        * Waiting time of HTTP response 
        */
        TInt iHttpResponseTime;
        
        /**
        * Is attached to connection
        */
        TBool iAttachDone;
    };

#endif // ICTSHTTPHANDLER_H