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