syncmlfw/common/http/inc/nsmlhttp.h
changeset 0 b497e44ab2fc
child 1 a9c0ce913924
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002-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 "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:  SyncML HTTP client
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef _SMLTRANSPORT_H_
       
    22 #define _SMLTRANSPORT_H_
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <e32cons.h>
       
    26 #include <reent.h>
       
    27 
       
    28 #include <http.h>
       
    29 #include <chttpformencoder.h>
       
    30 #include <mhttpauthenticationcallback.h>
       
    31 #include <e32test.h>
       
    32 #include <f32file.h>
       
    33 #include <uri8.h>
       
    34 #include <nifman.h>
       
    35 
       
    36 #include <nsmldebug.h>
       
    37 #include <nsmlconstants.h>
       
    38 #include <nsmldefines.h>
       
    39 
       
    40 #include "nsmltransport.h"
       
    41 #include "nsmldialiap.h"
       
    42 
       
    43 #include <rconnmon.h>
       
    44 
       
    45 // FORWARD DECLARATION
       
    46 class CNSmlXptShutdownTimer;
       
    47 class CNSmlHTTP;
       
    48 class CHttpEventHandler;
       
    49 //Class to observe the network status events 
       
    50 class CNsmlNetworkStatusEngine;
       
    51 // Reserved to maintain binary compability 
       
    52 class CNSmlFutureReservation;
       
    53 
       
    54 
       
    55 // Maximum size of buffer to hold content-type data
       
    56 //
       
    57 const TInt KMaxContentTypeSize = 256;
       
    58 // DM ONLY : Maximum duration in seconds for an incoming call  
       
    59 //during the session which will be used to decide if packet 
       
    60 //is to be resent or not . This is applicable only for DM 
       
    61 const TInt KDMMaxHttpAutoResumeDurationSec = 160;
       
    62 
       
    63 //============================================================
       
    64 // Class CNSmlHTTPErr
       
    65 //============================================================
       
    66 class TNSmlHTTPErrCode
       
    67 	{
       
    68 	public:	
       
    69 	enum 
       
    70 		{
       
    71 		/* 'Client Error' range of codes 4xx */
       
    72 		ENSmlHTTPErrCodeBase						= 1400,
       
    73 		ENSmlHTTPErr_BadRequest						= ENSmlHTTPErrCodeBase + HTTPStatus::EBadRequest,
       
    74 		ENSmlHTTPErr_Unauthorized					= ENSmlHTTPErrCodeBase + HTTPStatus::EUnauthorized,
       
    75 		ENSmlHTTPErr_PaymentRequired				= ENSmlHTTPErrCodeBase + HTTPStatus::EPaymentRequired,
       
    76 		ENSmlHTTPErr_Forbidden						= ENSmlHTTPErrCodeBase + HTTPStatus::EForbidden,
       
    77 		ENSmlHTTPErr_NotFound						= ENSmlHTTPErrCodeBase + HTTPStatus::ENotFound,
       
    78 		ENSmlHTTPErr_MethodNotAllowed				= ENSmlHTTPErrCodeBase + HTTPStatus::EMethodNotAllowed,
       
    79 		ENSmlHTTPErr_NotAcceptable					= ENSmlHTTPErrCodeBase + HTTPStatus::ENotAcceptable,
       
    80 		ENSmlHTTPErr_ProxyAuthenticationRequired	= ENSmlHTTPErrCodeBase + HTTPStatus::EProxyAuthenticationRequired,
       
    81 		ENSmlHTTPErr_RequestTimeout					= ENSmlHTTPErrCodeBase + HTTPStatus::ERequestTimeout,
       
    82 		ENSmlHTTPErr_Conflict						= ENSmlHTTPErrCodeBase + HTTPStatus::EConflict,
       
    83 		ENSmlHTTPErr_Gone							= ENSmlHTTPErrCodeBase + HTTPStatus::EGone,
       
    84 		ENSmlHTTPErr_LengthRequired					= ENSmlHTTPErrCodeBase + HTTPStatus::ELengthRequired,
       
    85 		ENSmlHTTPErr_PreconditionFailed				= ENSmlHTTPErrCodeBase + HTTPStatus::EPreconditionFailed,
       
    86 		ENSmlHTTPErr_RequestEntityTooLarge			= ENSmlHTTPErrCodeBase + HTTPStatus::ERequestEntityTooLarge,
       
    87 		ENSmlHTTPErr_RequestURITooLong				= ENSmlHTTPErrCodeBase + HTTPStatus::ERequestURITooLong,
       
    88 		ENSmlHTTPErr_UnsupportedMediaType			= ENSmlHTTPErrCodeBase + HTTPStatus::EUnsupportedMediaType,
       
    89 		ENSmlHTTPErr_RequestedRangeNotSatisfiable	= ENSmlHTTPErrCodeBase + HTTPStatus::ERequestedRangeNotSatisfiable,
       
    90 		ENSmlHTTPErr_ExpectationFailed				= ENSmlHTTPErrCodeBase + HTTPStatus::EExpectationFailed,
       
    91 		/* 'Server Error' range of codes 5xx */
       
    92 		ENSmlHTTPErr_InternalServerError			= ENSmlHTTPErrCodeBase + HTTPStatus::EInternalServerError,
       
    93 		ENSmlHTTPErr_NotImplemented					= ENSmlHTTPErrCodeBase + HTTPStatus::ENotImplemented,
       
    94 		ENSmlHTTPErr_BadGateway						= ENSmlHTTPErrCodeBase + HTTPStatus::EBadGateway,
       
    95 		ENSmlHTTPErr_ServiceUnavailable				= ENSmlHTTPErrCodeBase + HTTPStatus::EServiceUnavailable,
       
    96 		ENSmlHTTPErr_GatewayTimeout					= ENSmlHTTPErrCodeBase + HTTPStatus::EGatewayTimeout,
       
    97 		ENSmlHTTPErr_HTTPVersionNotSupported		= ENSmlHTTPErrCodeBase + HTTPStatus::EHTTPVersionNotSupported
       
    98 		};
       
    99 	};
       
   100 
       
   101 //============================================================
       
   102 // Class CNSmlXptShutdownTimer
       
   103 //============================================================
       
   104 class CNSmlXptShutdownTimer : public CActive
       
   105 	{
       
   106 	public:
       
   107 		// construct/destruct
       
   108 		CNSmlXptShutdownTimer( CNSmlHTTP* aEngine );
       
   109 		void ConstructL();
       
   110 		~CNSmlXptShutdownTimer();
       
   111 		// start timer
       
   112 		void Start();
       
   113 		void StartAborted();
       
   114 	private:
       
   115 		// from CActive
       
   116 		void DoCancel();
       
   117 		void RunL();
       
   118 		TTime iTimerSnapTime;
       
   119 	private:
       
   120 		RTimer iTimer;
       
   121 		CNSmlHTTP* iEngine; 
       
   122 	};
       
   123 
       
   124 //============================================================
       
   125 // Class CNSmlHTTP declaration
       
   126 //============================================================
       
   127 class CNSmlHTTP : public CActive, public MHTTPDataSupplier, public MHTTPAuthenticationCallback
       
   128 	{
       
   129 
       
   130 	public:
       
   131 		enum TEngineState {	ExptIdle, 
       
   132 							ExptOpenCommunication, 
       
   133 							ExptCloseCommunication,
       
   134 							ExptReceiveData, 
       
   135 							ExptSendData
       
   136 							};
       
   137 
       
   138 		enum TServerContentEncoding { ExptNone,
       
   139 		                              ExptDeflate
       
   140 	                            };
       
   141 
       
   142 	public:
       
   143 		// construct / destruct
       
   144 		static CNSmlHTTP* NewL();        
       
   145 		CNSmlHTTP();
       
   146 		virtual void ConstructL();
       
   147 		virtual ~CNSmlHTTP();
       
   148 
       
   149 		// syncml xpt api
       
   150 		virtual void OpenCommunicationL( CArrayFixFlat<TUint32>* aIAPidArray, TDesC8& aURI, TDesC8& aMimeType, TRequestStatus &aStatus, TDesC8& aHTTPusername, TDesC8& aHTTPpassword, TInt aHTTPauthused );
       
   151 		virtual void CloseCommunicationL( TRequestStatus &aStatus );
       
   152 		virtual void ReceiveDataL( TDes8& aStartPtr, TRequestStatus &aStatus );
       
   153 		virtual void SendDataL( TDesC8& aStartPtr, TBool aFinalPacket, TRequestStatus &aStatus );
       
   154 		virtual void ChangeTargetURIL( TDesC8& aURI );
       
   155 
       
   156 	    void CompleteRequest();
       
   157 		
       
   158 	public:
       
   159 		// methods inherited from MHTTPAuthenticationCallback
       
   160 		virtual TBool GetCredentialsL (const TUriC8 &aURI,RString aRealm,RStringF aAuthenticationType,RString &aUsername,RString &aPassword); 
       
   161 
       
   162 	public:
       
   163 		TRequestStatus* iAgentStatus;
       
   164 		//iPreemptRequest: Specifies how many requests were completed
       
   165 		//before the httpevent handler sends the status back.
       
   166 		//This can occur due to long wait time, http layer in some scenario sends
       
   167 		//status to client after 5-9 minutes
       
   168 		TInt iPreemptRequest;
       
   169         TBool iTimeOut;
       
   170 		TServerContentEncoding iServerContentEncoding;
       
   171 		TServerContentEncoding iServerAcceptEncoding;
       
   172 		TInt iMaxMsgSize;
       
   173 
       
   174 	private:
       
   175 		// methods inherited from MHTTPDataSupplier
       
   176 		TBool GetNextDataPart(TPtrC8& aDataPart);
       
   177 		void ReleaseData();
       
   178 		TInt OverallDataSize();
       
   179 		TInt Reset();
       
   180 		// from CActive
       
   181 		void DoCancel();
       
   182 		void RunL();
       
   183 		// set http error status
       
   184 		static TInt SetErrorStatus( TInt aError );
       
   185 		void ProcessRequestL();
       
   186 		void InvokeHttpMethodL( const TDesC8& aUri, RStringF aMethod );
       
   187 		void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue );
       
   188 		void GetResponseBodyL( TDes8& aStartPtr );
       
   189 		void SetHttpConnectionInfoL( TBool aUseOwnConnection );
       
   190 
       
   191 		void SaveCertificateL( RHTTPTransaction &aTransaction );
       
   192 		void DeleteCertificate();
       
   193 
       
   194 	
       
   195 		void CompressL(TDesC8& aStartPtr);
       
   196 		void DecompressL(TDes8& aStartPtr);
       
   197 		TInt ReadRepositoryL(TInt aKey, TInt& aValue);
       
   198 	private:
       
   199 		HBufC8* iData;
       
   200 		HBufC8* iReqBodySubmitBuffer;
       
   201 		TPtr8 iReqBodySubmitBufferPtr;
       
   202 
       
   203 		TInt iDocumentLength;
       
   204 		TInt iIAPid;
       
   205         CArrayFixFlat<TUint32>* iIAPidArray;
       
   206 		HBufC8* iURI;
       
   207 		HBufC8* iMimeType;
       
   208 		CNSmlDialUpAgent* iDialUpAgent;
       
   209 
       
   210 		HBufC8* iHTTPusername;
       
   211 		HBufC8* iHTTPpassword;
       
   212 		TInt iAuthUsed;		
       
   213 		TInt iAuthRetryCount;
       
   214 
       
   215 		// timer for closing transport activity
       
   216 		CNSmlXptShutdownTimer* iShutdown;
       
   217 		CNsmlNetworkStatusEngine* iNetworkStatusEngine;
       
   218 		TBool iLastPart;
       
   219 		TEngineState iEngineState;
       
   220 		RHTTPSession iSess;
       
   221 		RHTTPTransaction iTrans;
       
   222 		CHttpEventHandler* iTransObs;
       
   223 		// Reserved to maintain binary compability
       
   224 		CNSmlFutureReservation* iReserved;
       
   225 		//Stores the current ongoing session
       
   226 		TInt iSession;
       
   227 
       
   228 	private:
       
   229 		friend class CNSmlXptShutdownTimer;
       
   230 		friend class CHttpEventHandler;
       
   231 		friend class CNsmlNetworkStatusEngine;
       
   232 	};
       
   233 
       
   234 	IMPORT_C CNSmlHTTP* CreateCNSmlHTTPL();
       
   235 	typedef CNSmlHTTP* (*TNSmlCreateHTTPFunc) ();   
       
   236 
       
   237 
       
   238 
       
   239 
       
   240 //============================================================
       
   241 // Class CNsmlNetworkStatusEngine
       
   242 // This is used for listening for gprs suspend/resume events
       
   243 //============================================================
       
   244 
       
   245 
       
   246 class CNsmlNetworkStatusEngine :public CBase, private MConnectionMonitorObserver
       
   247 
       
   248 {
       
   249 		public:
       
   250         CNsmlNetworkStatusEngine( CNSmlHTTP* aAgent );
       
   251 		~CNsmlNetworkStatusEngine();
       
   252 		void ConstructL();
       
   253 	
       
   254     public: // New methods
       
   255         
       
   256       	/**
       
   257         * Starts notifications.
       
   258         */
       
   259 		void NotifyL() ;
       
   260 		
       
   261         /**
       
   262         * Stops notifications.
       
   263         */
       
   264        	void StopNotify() ;
       
   265        	
       
   266        	/**
       
   267         * Stops DM session.
       
   268         */
       
   269         void StopDMSession();
       
   270         			
       
   271 	private : // From MConnectionMonitorObserver
       
   272 		void EventL( const CConnMonEventBase& aConnMonEvent ) ;
       
   273 
       
   274 	private: // Data 
       
   275 	
       
   276 		RConnectionMonitor            iConnectionMonitor;
       
   277 		TRequestStatus                iStatus;
       
   278 		TInt                          iNetwStatus;
       
   279 		CNSmlHTTP* 	iAgent;
       
   280 		TBool iTimerOn;
       
   281 		CPeriodic*          iTimedExecuteStopSession;
       
   282 		TInt iDMSmlSessionTimeout;
       
   283 		TTime iSuspendedTime;
       
   284 		TTime iSuspendDuration;
       
   285 		
       
   286 };
       
   287 
       
   288 #endif