⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpengine.h

📁 symbian http/post引擎 xml引擎 支持IAP设置
💻 H
字号:
/*
* ============================================================================
*  Name     : CHttpEngine from HttpEngine.h
*  Part of  : 
*  Created  : 08/1/2008 by Forum Nokia
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

#ifndef __HTTPENGINE_H
#define __HTTPENGINE_H

// INCLUDE FILES
#include <http\mhttptransactioncallback.h>	//MHTTPTransactionCallback
#include <http\rhttpsession.h>				//RHTTPSession
#include <http\RHTTPTransaction.h>			//RHTTPTransaction
#include <http\rhttpheaders.h>				//RHTTPHeaders
#include <cdblen.h>							//KCommsDbSvrMaxFieldLength
#include <Es_sock.h>
#include <charconv.h>

#include "HttpConstants.h"

// FORWARD DECLARATIONS
class CHttpConnectionOpener;

class CHttpDataSupplier;

// CLASS DECLARATION

/**
* A mixin class for notifying about GPRS connection.
*/
class MConnectionObserver
	{
public:

	/**
	* Called when opening a GPRS connection has finished
	*/
	virtual void ConnectionCreated(const TInt& aError) = 0;
	};
	
	
// CLASS DECLARATION

/**
* A mixin class for notifying about HTTP transactions.
*/
class MTransactionObserver
	{
public:

	/**
	* Called when a GPRS connection is being opened.
	*/
	virtual void OpeningConnectionL() = 0;
	
	/**
	* Called when an HTTP transaction has successfully finished.
	* @param aResponse contains the response received from the server.
	*/
	virtual void SuccessL(const CResponse& aResponse) = 0;
	
	/**
	* Called when an HTTP transaction failed.
	* @param aError the error code.
	*/
	virtual void FailedL(const TInt& aError) = 0;
	
	/**
	* Called when an HTTP transaction is initiated.
	* @param aLoadingTasks ETrue if downloading tasks, EFalse if completing a task.
	*/
	virtual void ConnectingToServerL(const TBool& aLoadingTasks) = 0;
	
	/**
	* Called when user cancelled the HTTP transaction.
	*/
	virtual void CancelledL() = 0;
	
	/**
	* Called when user tries to initialise an HTTP transaction, but 
	* settings are faulty.
	* @param aErrorMsg error message.
	*/
	virtual void ErrorL(const TDesC& aErrorMsg) = 0;
	
	};


// CLASS DECLARATION

/**
* A class holding IAP data.
*/
class TIap
	{
public:
	TUint32 iId;
	TBuf<KCommsDbSvrMaxFieldLength> iName;
	};
	

// CLASS DECLARATION

/**
* An engine class.
* Used for posting requres to the server.
*/
class CHttpEngine :	public CBase,
							public MHTTPTransactionCallback,
							public MConnectionObserver
	{
public: // Constructors and destructor

	/**
	* Two-phased constructor.
	*/
	static CHttpEngine* NewL(MTransactionObserver& aObserver);

	/**
	* Destructor
	*/
	~CHttpEngine();
	
public: // New functions
	
	/**
	* Sets the connections settings.
	* @param aServerName name of the server.
	* @param aPhp if ETrue the server end is implemented with PHP, otherwise with JSP.
	* @param aUsername username.
	* @param aPassword password.
	*/
	void SetConnectionSettingsL(const TDesC& aServerName, 
								const TBool& aPhp,
								const TDesC& aUsername, 
								const TDesC& aPassword,
								const TUint32& aId);
								
	/**
	* With this function you can select which IAP is used for HTTP connection.
	* @param aId id of the IAP to be used.
	*/
	void SetIap(const TUint32& aId);
	
	/**
	* Will post an XML  to the server. As a result, we will get all tasks 
	* of the user.
	*/
	void PostRequestL(const TBool& aLoadingTask,const TDesC8& aBody);
	
	/**
	* Will post an HTML form to the server that is used for completing a wanted task.
	* @param aTaskId the id of the task that is to be completed.
	*/
	void MarkTaskDoneL(const TInt& aTaskId);
	
	/**
	* This method is used for cancelling an HTTP transaction or GPRS connection establishment.
	*/
	void CancelTransaction();
	
	/**
	* Returns whether IAP has been set or not.
	* @return ETrue if IAP is set, EFalse if not.
	*/
	TBool IapSet() const;
	
	/**
	* Returns all found IAPs.
	* @return reference to an array of IAPs.
	*/
	RArray<TIap>& Iaps();

	/**
	* Checks if a postponed fetch request had been made during a transaction. If so,
 	* starts the fetching process.
	*/
	void CheckRefreshL();
	
	/**
	* This function sets the automatic task loading on or off. If this functionality 
	* is set on, tasks are loaded automatically when an update SMS message is received.
	* @param aOn ETrue if tasks are loaded automatically, EFalse if not.
	*/
	void SetAutomaticUpdateL(const TBool& aOn);
	
	void ConvGbk2Uni(TDesC8& original, TDes& res,TUint characterSetIdentifier=KCharacterSetIdentifierGbk); 
	
	void ConvUni2Gbk(TDesC& original, TDes8& res,TUint characterSetIdentifier=KCharacterSetIdentifierGbk);
		
private: // Functions from base classes

	/**
	* From MHTTPTransactionCallback
	*/
	void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);

	/**
	* From MHTTPTransactionCallback
	*/
	TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
	
	/**
	* FROM MConnectionObserver
	*/
	void ConnectionCreated(const TInt& aError);
		
private: // New functions

	/**
	* Creates a HTML form which can be post to the server for completing a task.
	* @param aTaskId id of the task that is to be completed.
	*/
	void CreateMarkTaskDoneFormL(const TInt& aTaskId);
	
	/**
	* Resets the previously received data (that is set by WriteDataL()).
	*/
	void ResetData();
	
	/**
	* Set a field-value pair for the given HTTP header.
	* @param aHeaders header where field-value pair is written.
	* @param aHdrField field that is written to the header.
	* @param aHdrValue value that is assigned for the field.
	*/
	void SetHeaderL(RHTTPHeaders aHeaders, 
			 		TInt aHdrField, 
			 		const TDesC8& aHdrValue);
	
	/**
	* Set a field-value pair for the given HTTP header.
	* @param aHeaders header where field-value pair is written.
	* @param aHdrField field that is written to the header.
	* @param aHdrValue value that is assigned for the field.
	*/
	void SetHeaderExL(RHTTPHeaders aHeaders,
					const TDesC8 &aHeaderField, 
					const TDesC8 &aHeaderValue);

	/**
	* Loads all IAPs of a device into an array.
	*/		 		
	void LoadIapsL();
	
	/**
	* Opens up a (GPRS) connection if one does not yet exist.
	*/
	void ConnectL();
	
	/**
	* Checks that server name and an IAP is set. Reports about "errors" with 
	* MTransactionObserver::ErrorL();
	* @return ETrue if errors existed, EFalse if not.
	*/
	TBool CheckAndReportErrorsL();
	
	/**
	* Posts data to the server.
	*/
	void DoPostL();

private:

	/**
	* Symbian OS default constructor
	*/
	CHttpEngine(MTransactionObserver& aObserver);
	void ConstructL();
	
private: // Data members

	RConnection						iConnection;
	RSocketServ						iSockServ;
	RHTTPSession					iHttpSession;
	RHTTPTransaction				iTransaction;
   
	MTransactionObserver&			iTransactionObserver;
	CHttpConnectionOpener*			iConnOpener;
	HBufC8*							iReceivedData;
	TBuf8<KMaxUsernameLength>		iUsername;
	TBuf8<KMaxPasswordLength>		iPassword;
	TBuf8<KMaxServerNameLength>		iServer;
	TBool							iRunning;
	TBool							iLoadingTask;
	TBool							iDoRefresh;//受到短信,更新任务标志
	TBool							iOpeningConnection;
	TBool							iPhp;
	RArray<TIap>					iIAPs;
	TUint32							iIap;
	TBool							iAutomaticUpdate;
	TBuf8<KMaxServerNameLength+40>	iUrl;
	CHttpDataSupplier*				iDataSupplier;
	};

#endif

// End of file




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -