epoc32/include/mw/http/framework/cprotocolhandler.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/http/framework/cprotocolhandler.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // please do not delete
    15 // 
    16 //
    17 
    18 
    19 
    20 /**
    21  @file CProtocolHandler.h
    22  @warning : This file contains Rose Model ID comments 
    23 */
    24 
    25 #ifndef __CPROTOCOLHANDLER_H__
    26 #define __CPROTOCOLHANDLER_H__
    27 
    28 // System includes
    29 #include <e32base.h>
    30 #include <http/framework/httplogger.h>
    31 #include <http/mhttpfilter.h>
    32 #include <http/rhttpsession.h>
    33 
    34 // Forward declarations
    35 class CHeaderCodec;
    36 class CProtTransaction;
    37 class CSecurityPolicy;
    38 class MProtHandlerInterface;
    39 
    40 /**
    41 The ECom protocol handler plugin interface UID.
    42 @publishedAll
    43 @released
    44 */
    45 const TUid KUidProtocolHandlerPluginInterface = {0x1000A449};
    46 
    47 // 
    48 /**
    49 Defined active object priorities for the Protocol Handler
    50 @publishedAll
    51 @released
    52 */
    53 const TInt KProtocolHandlerActivePriority = CActive::EPriorityStandard;
    54 /**
    55 Defined active object priorities for the Transaction
    56 @publishedAll
    57 @released
    58 */
    59 const TInt KTransactionActivePriority = KProtocolHandlerActivePriority+1;
    60 
    61 
    62 //##ModelId=3C4C186A02A3
    63 class CProtocolHandler : public CActive, public MHTTPFilter
    64 /**
    65 An abstract protocol handler.  Protocol handlers are required to
    66 act as the bridge between abstract representations of sessions, transactions and
    67 headers (the client side of the HTTP architecture) and specific comms transports
    68 (the network side of the architecture).
    69 
    70 Each instance of a concrete subclass of CProtocolHandler is associated
    71 with a specific	client session, and hence with a particular choice of proxy type,
    72 and by implication, transport type.  It is designed to appear like a filter in
    73 order to be placed at the end of a session's filter queue.  This allows it to 
    74 receive transaction-related events in the same way that any other filter
    75 (or indeed, the client) does.  An active object, it may implement a queuing
    76 system for submitted transactions, according to the chosen internal service
    77 model.
    78 
    79 In order to divide the abstract functionality associated with handling the HTTP
    80 protocol handler from the specifics needed for a particular choice of transport,
    81 this class defines a number of pure virtual methods which allow it to defer
    82 transport-specific choices or mechamisms.  These are mainly concerned with the
    83 service model (ie. allocation of transactions to objects that can handle them), the
    84 codec model (ie. on-demand encoding/decoding of	HTTP header data) and general
    85 housekeeping (eg. instantiation and cleanup of objects at particular points in
    86 a transaction lifecycle).
    87 @publishedAll
    88 @released
    89 */
    90 	{
    91 public:	// Methods
    92 
    93 /**	
    94 	Standard factory constructor. This is the ECOM interface class from
    95 	which concrete protocol handlers are derived. The method queries
    96 	ECOM for the protocol handler plugin that matches the protocol
    97 	description passed in.
    98 	@param			aProtocol	(in) The name of the protocol required.
    99 	@param			aSession	(in) The HTTP session on which this protocol handler
   100 									 will be installed.
   101 	@leave			KErrNoMemory if there was not enough memory to create the object.
   102 */
   103 	//##ModelId=3C4C186B007E
   104 	static CProtocolHandler* NewL(const TDesC8& aProtocol, RHTTPSession aSession);
   105 
   106 /**	
   107 	Intended Usage:	Class destructor.
   108 */
   109 	//##ModelId=3C4C186B0075
   110 	IMPORT_C virtual ~CProtocolHandler();
   111 
   112 /**	
   113 	Obtain the protocol handler's header codec.
   114 	@return			The header codec owned by this protocol handler, or NULL if one
   115 					has not yet been created.
   116 	@see CHeaderCodec
   117 */
   118 	//##ModelId=3C4C186B0074
   119 	IMPORT_C CHeaderCodec* Codec() const;
   120 
   121 
   122 /** 
   123 	Get the Server Certificate for the current session.
   124 	@return	The certificate information or NULL if it is not available
   125 */
   126 	IMPORT_C const CCertificate* SessionServerCert();
   127 
   128 /** 
   129 	Get the Server Certificate for the specified transaction.
   130 	@param	aTransaction The transaction for which the certificate is requested
   131 	@return	The certificate information or NULL if it is not available
   132 */
   133 	IMPORT_C const CCertificate* TransactionServerCert( RHTTPTransaction aTransaction);
   134 
   135 public:	// Methods to be implemented in specific protocol handlers
   136 
   137 /** 
   138 	Intended Usage:	Get the Server Certificate for the current session.
   139 	@param	aServerCert A TCertInfo which will be filled with the certificate information
   140 	@return	An error code.  KErrNone if aServerCert has been completed, otherwise one of 
   141 	the system wide error codes
   142 */
   143 	virtual TInt SessionServerCert(TCertInfo& aServerCert) = 0;
   144 
   145 /** 
   146 	Intended Usage:	Get the Server Certificate for the specified transaction.
   147 	@param	aServerCert A TCertInfo which will be filled with the certificate information
   148 	@param	aTransaction The transaction for which the certificate is requested
   149 	@return	An error code.  KErrNone if aServerCert has been completed, otherwise one of 
   150 			the system wide error codes
   151 */
   152 	virtual TInt TransactionServerCert(TCertInfo& aServerCert, RHTTPTransaction aTransaction) = 0;
   153 
   154 public:	// Methods from MHTTPFilterBase
   155 	
   156 /**
   157 	Intended Usage:	Called when the filter's registration conditions are satisfied for events that
   158 	occur on a transaction. Any Leaves must be handled by the appropriate MHFRunError.
   159 	Note that this function is not allowed to leave if called with certain events. 
   160 	@see THTTPEvent
   161 	@param aTransaction The transaction that the event has occurred on.
   162 	@param aEvent aEvent The event that has occurred.
   163 	@leave Standard Symbian OS error codes. e.g. KErrNoMemory.
   164 	@see MHTTPFilterBase	
   165 */
   166 	//##ModelId=3C4C186B0061
   167 	IMPORT_C virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
   168 
   169 /**
   170 	Intended Usage:	Called when the filters registration conditions are satisfied for events that occur
   171 	on the session. Any leaves must be handled by the appropriate MHFRunError.
   172 	@param aEvent The session event that has occured.
   173 	@leave KErrNoMemory if an attempt to allocate memory has failed
   174 	@leave KErrHttpCantResetRequestBody if the request body needed to be rewound by the client
   175 		   but it doesn't support this
   176 	@see MHTTPFilterBase
   177 */
   178 	//##ModelId=3C4C186B0057
   179 	IMPORT_C virtual void MHFSessionRunL(const THTTPSessionEvent& aEvent);
   180 
   181 /**
   182 	Intended Usage:	Called when RunL leaves from a transaction event. This works in the same
   183 	way as CActve::RunError; return KErrNone if you have handled the error.
   184 	If you don't completely handle the error, a panic will occur.
   185 	@param aError The leave code that RunL left with.
   186 	@param aTransaction The transaction that was being processed.
   187 	@param aEvent The Event that was being processed.
   188 	@return KErrNone if the error has been cancelled or the code
   189 			of the continuing error otherwise.
   190 	@see MHTTPFilterBase
   191 */
   192 	//##ModelId=3C4C186B0043
   193 	IMPORT_C virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
   194 
   195 /**
   196 	Intended Usage:	Called when MHFRunL leaves from a session event. This works in the same
   197 	way as CActve::RunError. If you don't completely handle the error, a panic will occur.
   198 	@param aError The leave code that RunL left with.
   199 	@param aEvent The Event that was being processed.
   200 	@return KErrNone if the error has been cancelled or the code
   201 			of the continuing error otherwise.	
   202 	@see MHTTPFilterBase
   203 */
   204 	//##ModelId=3C4C186B0038	
   205 	IMPORT_C virtual TInt MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent);
   206 
   207 public:	// Methods from MHTTPFilter
   208 
   209 /** 
   210 	Intended Usage:	Called when the filter is being removed from a session's filter queue.
   211 	@param aSession The session it's being removed from
   212 	@param aHandle The filter handle. Complex filters may need to 
   213 				   refer to this to keep track of which particular registration is
   214 				   being unloaded.
   215 	@see MHTTFilter
   216 */
   217 	//##ModelId=3C4C186B0025
   218 	IMPORT_C virtual void MHFUnload(RHTTPSession aSession, THTTPFilterHandle aHandle);
   219 
   220 /** 
   221 	Intended Usage:	Called when the filter is being added to the session's filter queue.
   222 	@param aSession The session it's being added to.
   223 	@param aHandle The filter handle. Complex filters may need to keep
   224 				   track of this, for instance if generating events in response to
   225 				   external stimuli
   226 	@see MHTTFilter
   227  */
   228 	//##ModelId=3C4C186B001A
   229 	IMPORT_C virtual void MHFLoad(RHTTPSession aSession, THTTPFilterHandle aHandle);
   230 
   231 protected: // callbacks/methods for sub-classes
   232 
   233 /**	
   234 	Callback method for concrete protocol handler sub-classes to
   235 	inform the base protocol handler that a transaction has completed.
   236 	The concrete protocol handler must call this method in order to
   237 	supply a completion event that will be sent to the client.
   238 	In addition, the method allows the base protocol handler to do some
   239 	queue management.
   240 	@param			aTrans			(in) the completed transaction
   241 	@param			aEventStatus	(in) an event to be sent back to the client along
   242 										 the filter queue
   243 	@leave			THTTPPanic::EInvalidFilterHandle if unable to send event.
   244  */
   245 	//##ModelId=3C4C186B0010
   246 	IMPORT_C void TransactionCompletedL(RHTTPTransaction aTrans, THTTPEvent aEventStatus);
   247 
   248 /**	
   249 	Obtain the number of currently active transactions
   250 	@return			The number of currently active transactions
   251  */
   252 	//##ModelId=3C4C186B0006
   253 	IMPORT_C TInt NumActiveTransactions() const;
   254 
   255 /**	
   256 	Callback method for concrete protocol handler sub-classes to
   257 	inform the base protocol handler that a transaction has failed
   258 	utterly. (i.e. the sub-class used aTrans.Fail().) The base protocol
   259 	handler sets the transaction state to be cancelled.
   260 	@param			aTrans			(in) the completed transaction
   261  */
   262 	//##ModelId=3C4C186A03E5
   263 	IMPORT_C void TransactionFailed(RHTTPTransaction aTrans);
   264 
   265 /**	
   266 	Completes this active object - allows the protocol handler to
   267 	reevaluate the queue of pending transactions and service new ones
   268 	if possible.
   269  */
   270 	//##ModelId=3C4C186A03E4
   271 	IMPORT_C void CompleteSelf();
   272 
   273 /**	
   274 	Searches the array of CProtTransaction objects to if the
   275 	aTransaction object is wrapped by one of them. If one is found aProtTransaction is set to it
   276 	@param aTransaction	The transaction to search for.
   277 	@param aProtTransaction	Reference to a CProtTransaction which will be set to the
   278 		   CProtTransaction which wraps the RHTTPTransaction.
   279 	@return If a CProtTransaction object is found, a positive value is
   280 			returned that is the index to that object in the array. If 
   281 			no object is found, KErrNotFound is returned.
   282  */
   283 	IMPORT_C TInt FindTransaction(RHTTPTransaction aTransaction, const CProtTransaction*& aProtTransaction) const;
   284 
   285 private: // methods to be implemented in specific protocol handlers
   286 
   287 /**	Intended usage:	Creates the specific type of codec required for a specific type
   288 					of protocol handler.
   289 					
   290 					This must be implemented by a concrete protocol handler sub-class.
   291  */
   292 	//##ModelId=3C4C186A03DC
   293 	virtual void CreateCodecL() = 0;
   294 
   295 /**	Intended Usage:	Creates a representation of a client transaction to be used in the
   296 					protocol handler.  Since the protocol handler deals with the low-
   297 					level data for a transaction as sent over a particular transport,
   298 					an appropriate CProtTransaction-derived class is used that owns a
   299 					CRxData and a CTxData to handle the low-level data.
   300 					
   301 					This must be implemented by a concrete protocol handler sub-class.
   302 	@leave			KErrNoMemory if there was not enough memory to create the object.
   303 					create the object.
   304 	@param			aTransaction	The RHTTPTransaction object associated with
   305 									this CProtTransaction object.
   306 	@return			A pointer to a created CProtTransaction-derived class.
   307 	@see			CRxData
   308 	@see			CTxData
   309  */
   310 	//##ModelId=3C4C186A03DA
   311 	virtual CProtTransaction* CreateProtTransactionL(RHTTPTransaction aTransaction) = 0;
   312 
   313 /**	Intended Usage:	Attempt to service the transaction.  This implies that the concrete
   314 					protocol handler will allocate some transport resources to the
   315 					transaction - which could fail if the protocol handler has hit an
   316 					internal limit of resources or bandwidth.
   317 					Implementations of this interface may leave with any of KErrHttpInvalidUri,
   318 					KErrGeneral, KErrNoMemory
   319 					
   320 					This must be implemented by a concrete protocol handler sub-class.
   321 	@param			aTrans	The pending protocol transaction object which is to be
   322 							serviced.
   323 	@return			A flag that indicates if the transaction can be serviced immediately.
   324  */
   325 	//##ModelId=3C4C186A03D0
   326 	virtual TBool ServiceL(CProtTransaction& aTrans) = 0;
   327 
   328 /**	Intended Usage:	Called when the RHTTPTransaction object corresponding to aTrans has
   329 					been closed by the client. This allows the concrete protocol handler
   330 					to do any cleanup required for this particular transaction.
   331 
   332 					Ownership of the CProtTransaction object is transferred back to the
   333 					concrete protocol handler, which then has deletion responsibility
   334 					for it.  By the time this function has been called, the base
   335 					protocol handler will have dequeued the transaction.
   336 					
   337 					The client's RHTTPTransaction will be closed when this function
   338 					returns,  so it is not possible to send events to the client during
   339 					the function's execution.
   340 					
   341 					This must be implemented by a concrete protocol handler sub-class.
   342 	@param			aTrans		(in) A pointer to the transaction about to be closed.
   343  */
   344 	//##ModelId=3C4C186A03C6
   345 	virtual void ClosedTransactionHook(CProtTransaction* aTrans) = 0;
   346 
   347 /**	Intended Usage:	Called when the RHTTPTransaction object corresponding to aTrans has
   348 					been cancelled by the client or an intermediate filter. This allows
   349 					the concrete protocol handler to do any cleanup and to perform the
   350 					necessary actions for cancellation on its transport layer.
   351 					
   352 					This must be implemented by a concrete protocol handler sub-class.
   353 	@param			aTrans		(in) A reference to the transaction being cancelled.
   354  */
   355 	//##ModelId=3C4C186A03B3
   356 	virtual void CancelTransactionHook(CProtTransaction& aTransaction) = 0;
   357 
   358 /**	Intended Usage:	Called to notify the concrete protocol handler that new request
   359 					body data is available for transmission.
   360 					
   361 					This must be implemented by a concrete protocol handler sub-class.
   362 	@param			aTrans		(in) A reference to the transaction whose request body
   363 									 has new data available.
   364  */
   365 	//##ModelId=3C4C186A03A8
   366 	virtual void NotifyNewRequestBodyPart(CProtTransaction& aTransaction) = 0;
   367 
   368 protected: // Methods inherited from CActive
   369 
   370 /**	Intended Usage:	Do some processing when a previous asynchronous request made by
   371 					this object has completed.
   372  */
   373 	//##ModelId=3C4C186A0377
   374 	IMPORT_C virtual void RunL();
   375 
   376 /**	Intended Usage:	Do any cleanup required should RunL leave
   377 	@param			aError		(in) The error code that RunL left with
   378 	@return			A final error code - KErrNone if the error was handled by this
   379 					method.
   380  */
   381 	//##ModelId=3C4C186A036E
   382 	IMPORT_C virtual TInt RunError(TInt aError);
   383 
   384 /**	Intended Usage:	Cancel outstanding asynchronous requests that this object has made
   385  */
   386 	//##ModelId=3C4C186A036D
   387 	IMPORT_C virtual void DoCancel();
   388 
   389 protected:	// Methods
   390 
   391 /**	
   392 	Constructs a protocol handler associated with the supplied HTTP
   393 	client session.
   394 	@param			aSession	(in) The session on which the new protocol handler will
   395 									 be installed.
   396  */
   397 	IMPORT_C CProtocolHandler(RHTTPSession aSession);
   398 
   399 /**	
   400 	Second phase construction in which any necessary allocation is done
   401 	Implementations of this interface may leave with KErrNoMemory
   402 	@param aSession The HTTP session on which this protocol handler
   403 		   will be installed.
   404  */
   405 	//##ModelId=3C4C186A036C
   406 	IMPORT_C void ConstructL(RHTTPSession aSession);
   407 
   408 protected: // Attributes
   409 
   410 	/** The session to which this protocol handler is dedicated
   411 	*/
   412 	//##ModelId=3C4C186A033C
   413 	RHTTPSession iSession;
   414 
   415 	/** The codec used for this protocol handler (to be specialised in subclasses)
   416 	*/
   417 	//##ModelId=3C4C186A032F
   418 	CHeaderCodec* iCodec;
   419 
   420 	/** HTTP logger handle (debug only)
   421 	*/
   422 	__DECLARE_LOG
   423 
   424 	/** An interface providing the security policy. This may be NULL if there is no security policy plugin */
   425 	//##ModelId=3C4C186A031D
   426 	CSecurityPolicy* iSecurityPolicy;	
   427 
   428 private: // Methods
   429 
   430 /**	
   431 	Called after a client RHTTPTransaction::SubmitL(), this method
   432 	enqueues the supplied client transaction.  It checks to see if there
   433 	already exists a CProtTransaction for this transaction. If there is
   434 	and its state is ECancelled, then the associated request data is
   435 	reset and the state changed to EPending. A CompleteSelf() is issued.
   436 	In the case of an existing CProtTransaction that has not been
   437 	cancelled, the submit event is ignored. If no CProtTransaction
   438 	object existed, then one is created for the transaction and a
   439 	CompleteSelf() is issued.
   440 	@leave			KErrHttpCantResetRequestBody if the request body data cannot
   441 					be reset. KErrNoMemory if a new CProtTransaction cannot be
   442 					created or added to the transaction queue.
   443 	@param			aTransaction	The submitted transaction.
   444 	@pre 			None
   445 	@post			If there is a new pending CProtTransaction object the protocol
   446 					handler will have been self-completed (i.e. the RunL will be 
   447 					called).
   448  */
   449 	//##ModelId=3C4C186A0362
   450 	void SubmitTransactionL(RHTTPTransaction aTransaction);
   451 
   452 /**	
   453 	Sets the state of the CProtTransaction object for this 
   454 	transaction to ECancelled, and resets the object. This
   455 	object can be reused if the transaction is resubmitted.
   456 	@param			RHTTPTransaction aTrans
   457 	@pre 			A CProtTransaction object exists for this transaction.
   458 	@post			The state of the CProtTransaction object is set to ECancelled 
   459 					and it has been reset.
   460  */
   461 	//##ModelId=3C4C186A0359
   462 	void HandleCancelTransaction(RHTTPTransaction aTrans);
   463 
   464 /**	
   465 	Removes the CProtTransaction object for the transaction
   466 	from the queue of CProtTransaction objects.
   467 	@param			RHTTPTransaction aTrans
   468 	@pre 			A CProtTransaction object exists for this transaction.
   469 	@post			The CProtTransaction object has been removed from the queue.
   470  */
   471 	//##ModelId=3C4C186A034F
   472 	void HandleClosedTransaction(RHTTPTransaction aTrans);
   473 
   474 /**	
   475 	Searches the array of CProtTransaction objects to if the
   476 	aTransaction object is wrapped by one of them.
   477 	@param			aTransaction	The transaction to search for.
   478 	@return			If a CProtTransaction object is found, a positive value is
   479 					returned that is the index to that object in the array. If 
   480 					no object is found, KErrNotFound is returned.
   481  */
   482 	//##ModelId=3C4C186A0346
   483 	TInt FindTransaction(RHTTPTransaction aTransaction) const;
   484 
   485 protected:
   486 /**	
   487 	Intended Usage: This is a mechanism for allowing future change to CProtocolHandler API 
   488 	without breaking BC.
   489 	@param aInterfaceId		the UID of the API function being called.
   490 	@param aInterfacePtr	reference to pointer to actual function implementation (in the derived class)
   491  */
   492 	inline virtual void GetInterfaceL(TUid aInterfaceId, MProtHandlerInterface*& aInterfacePtr);
   493 
   494 public:
   495 /**	Intended Usage:	Reserve a slot in the v-table to preserve future BC
   496  */
   497 	//##ModelId=3C4C186A0344
   498 	inline virtual void Reserved2();
   499 
   500 
   501 private: // Attributes
   502 
   503 	/** A list of transactions. Each transaction has a list state, e.g. pending,
   504 		active, etc.
   505 	*/
   506 	//##ModelId=3C4C186A0313
   507 	RPointerArray<CProtTransaction>		iTransactions;
   508 
   509 	/**	The transaction which is currently being serviced - used in RunError so 
   510 		we know which transaction caused RunL to leave.
   511 	*/
   512 	//##ModelId=3C4C186A02FF
   513 	RHTTPTransaction					iCurrentTransaction;
   514 
   515 	/** The destructor key UID indentification required by ECom
   516 	*/
   517 	//##ModelId=3C4C186A02F5
   518 	TUid iDtor_ID_Key;
   519 	};
   520 
   521 
   522 	
   523 /**
   524 Interface for adding to ProtocolHandler API
   525 @publishedAll
   526 @released
   527 */
   528 
   529 const TInt KProtHandlerSessionServerCertUid		= 0x1028180D;
   530 const TInt KProtHandlerTransactionServerCertUid	= 0x1028180E;
   531 
   532 class MProtHandlerInterface
   533 	{
   534 public:
   535 	/** 
   536 	Intended Usage: Get the Server Certificate for the current session.
   537 	@return	The certificate information or NULL if it is not available
   538 	*/
   539 	virtual const CCertificate*  SessionServerCert() = 0;
   540 
   541 	/** 
   542 	Intended Usage: Get the Server Certificate for the specified transaction.
   543 	@param	aTransaction The transaction for which the certificate is requested
   544 	@return	The certificate information or NULL if it is not available
   545 	*/
   546 	virtual const CCertificate* TransactionServerCert( RHTTPTransaction aTransaction) = 0;
   547 	};
   548 
   549 inline void CProtocolHandler::GetInterfaceL(TUid, MProtHandlerInterface*&)
   550 	{}
   551 
   552 inline void CProtocolHandler::Reserved2()
   553 	{}
   554 
   555 #endif // __CPROTOCOLHANDLER_H__