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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // please do not delete
19 @file CProtocolHandler.h
20 @warning : This file contains Rose Model ID comments
23 #ifndef __CPROTOCOLHANDLER_H__
24 #define __CPROTOCOLHANDLER_H__
28 #include <http/framework/httplogger.h>
29 #include <http/mhttpfilter.h>
30 #include <http/rhttpsession.h>
32 // Forward declarations
34 class CProtTransaction;
35 class CSecurityPolicy;
36 class MProtHandlerInterface;
39 The ECom protocol handler plugin interface UID.
43 const TUid KUidProtocolHandlerPluginInterface = {0x1000A449};
47 Defined active object priorities for the Protocol Handler
51 const TInt KProtocolHandlerActivePriority = CActive::EPriorityStandard;
53 Defined active object priorities for the Transaction
57 const TInt KTransactionActivePriority = KProtocolHandlerActivePriority+1;
60 //##ModelId=3C4C186A02A3
61 class CProtocolHandler : public CActive, public MHTTPFilter
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).
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
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).
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
99 @leave KErrNoMemory if there was not enough memory to create the object.
101 //##ModelId=3C4C186B007E
102 static CProtocolHandler* NewL(const TDesC8& aProtocol, RHTTPSession aSession);
105 Intended Usage: Class destructor.
107 //##ModelId=3C4C186B0075
108 IMPORT_C virtual ~CProtocolHandler();
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.
116 //##ModelId=3C4C186B0074
117 IMPORT_C CHeaderCodec* Codec() const;
121 Get the Server Certificate for the current session.
122 @return The certificate information or NULL if it is not available
124 IMPORT_C const CCertificate* SessionServerCert();
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
131 IMPORT_C const CCertificate* TransactionServerCert( RHTTPTransaction aTransaction);
133 public: // Methods to be implemented in specific protocol handlers
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
141 virtual TInt SessionServerCert(TCertInfo& aServerCert) = 0;
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
150 virtual TInt TransactionServerCert(TCertInfo& aServerCert, RHTTPTransaction aTransaction) = 0;
152 public: // Methods from MHTTPFilterBase
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.
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.
164 //##ModelId=3C4C186B0061
165 IMPORT_C virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
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
176 //##ModelId=3C4C186B0057
177 IMPORT_C virtual void MHFSessionRunL(const THTTPSessionEvent& aEvent);
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.
190 //##ModelId=3C4C186B0043
191 IMPORT_C virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
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.
202 //##ModelId=3C4C186B0038
203 IMPORT_C virtual TInt MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent);
205 public: // Methods from MHTTPFilter
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
215 //##ModelId=3C4C186B0025
216 IMPORT_C virtual void MHFUnload(RHTTPSession aSession, THTTPFilterHandle aHandle);
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
226 //##ModelId=3C4C186B001A
227 IMPORT_C virtual void MHFLoad(RHTTPSession aSession, THTTPFilterHandle aHandle);
229 protected: // callbacks/methods for sub-classes
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
238 @param aTrans (in) the completed transaction
239 @param aEventStatus (in) an event to be sent back to the client along
241 @leave THTTPPanic::EInvalidFilterHandle if unable to send event.
243 //##ModelId=3C4C186B0010
244 IMPORT_C void TransactionCompletedL(RHTTPTransaction aTrans, THTTPEvent aEventStatus);
245 IMPORT_C TInt TransactionCompleted(RHTTPTransaction aTrans, THTTPEvent aEventStatus);
247 Obtain the number of currently active transactions
248 @return The number of currently active transactions
250 //##ModelId=3C4C186B0006
251 IMPORT_C TInt NumActiveTransactions() const;
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
260 //##ModelId=3C4C186A03E5
261 IMPORT_C void TransactionFailed(RHTTPTransaction aTrans);
264 Completes this active object - allows the protocol handler to
265 reevaluate the queue of pending transactions and service new ones
268 //##ModelId=3C4C186A03E4
269 IMPORT_C void CompleteSelf();
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.
281 IMPORT_C TInt FindTransaction(RHTTPTransaction aTransaction, const CProtTransaction*& aProtTransaction) const;
283 IMPORT_C CProtTransaction* FindProtocolTransaction(RHTTPTransaction aTransaction) const;
284 private: // methods to be implemented in specific protocol handlers
286 /** Intended usage: Creates the specific type of codec required for a specific type
289 This must be implemented by a concrete protocol handler sub-class.
291 //##ModelId=3C4C186A03DC
292 virtual void CreateCodecL() = 0;
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.
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.
303 @param aTransaction The RHTTPTransaction object associated with
304 this CProtTransaction object.
305 @return A pointer to a created CProtTransaction-derived class.
309 //##ModelId=3C4C186A03DA
310 virtual CProtTransaction* CreateProtTransactionL(RHTTPTransaction aTransaction) = 0;
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
319 This must be implemented by a concrete protocol handler sub-class.
320 @param aTrans The pending protocol transaction object which is to be
322 @return A flag that indicates if the transaction can be serviced immediately.
324 //##ModelId=3C4C186A03D0
325 virtual TBool ServiceL(CProtTransaction& aTrans) = 0;
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.
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.
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.
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.
343 //##ModelId=3C4C186A03C6
344 virtual void ClosedTransactionHook(CProtTransaction* aTrans) = 0;
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.
351 This must be implemented by a concrete protocol handler sub-class.
352 @param aTrans (in) A reference to the transaction being cancelled.
354 //##ModelId=3C4C186A03B3
355 virtual void CancelTransactionHook(CProtTransaction& aTransaction) = 0;
357 /** Intended Usage: Called to notify the concrete protocol handler that new request
358 body data is available for transmission.
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.
364 //##ModelId=3C4C186A03A8
365 virtual void NotifyNewRequestBodyPart(CProtTransaction& aTransaction) = 0;
367 protected: // Methods inherited from CActive
369 /** Intended Usage: Do some processing when a previous asynchronous request made by
370 this object has completed.
372 //##ModelId=3C4C186A0377
373 IMPORT_C virtual void RunL();
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
380 //##ModelId=3C4C186A036E
381 IMPORT_C virtual TInt RunError(TInt aError);
383 /** Intended Usage: Cancel outstanding asynchronous requests that this object has made
385 //##ModelId=3C4C186A036D
386 IMPORT_C virtual void DoCancel();
388 protected: // Methods
391 Constructs a protocol handler associated with the supplied HTTP
393 @param aSession (in) The session on which the new protocol handler will
396 IMPORT_C CProtocolHandler(RHTTPSession aSession);
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
404 //##ModelId=3C4C186A036C
405 IMPORT_C void ConstructL(RHTTPSession aSession);
407 protected: // Attributes
409 /** The session to which this protocol handler is dedicated
411 //##ModelId=3C4C186A033C
412 RHTTPSession iSession;
414 /** The codec used for this protocol handler (to be specialised in subclasses)
416 //##ModelId=3C4C186A032F
417 CHeaderCodec* iCodec;
419 /** HTTP logger handle (debug only)
423 /** An interface providing the security policy. This may be NULL if there is no security policy plugin */
424 //##ModelId=3C4C186A031D
425 CSecurityPolicy* iSecurityPolicy;
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.
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
448 //##ModelId=3C4C186A0362
449 void SubmitTransactionL(RHTTPTransaction aTransaction);
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.
460 //##ModelId=3C4C186A0359
461 void HandleCancelTransaction(RHTTPTransaction aTrans);
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.
470 //##ModelId=3C4C186A034F
471 void HandleClosedTransaction(RHTTPTransaction aTrans);
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.
481 //##ModelId=3C4C186A0346
482 TInt FindTransaction(RHTTPTransaction aTransaction) const;
486 Intended Usage: This is a mechanism for allowing future change to CProtocolHandler API
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)
491 inline virtual void GetInterfaceL(TUid aInterfaceId, MProtHandlerInterface*& aInterfacePtr);
494 /** Intended Usage: Reserve a slot in the v-table to preserve future BC
496 //##ModelId=3C4C186A0344
497 inline virtual void Reserved2();
500 private: // Attributes
502 /** A list of transactions. Each transaction has a list state, e.g. pending,
505 //##ModelId=3C4C186A0313
506 RPointerArray<CProtTransaction> iTransactions;
508 /** The transaction which is currently being serviced - used in RunError so
509 we know which transaction caused RunL to leave.
511 //##ModelId=3C4C186A02FF
512 RHTTPTransaction iCurrentTransaction;
514 /** The destructor key UID indentification required by ECom
516 //##ModelId=3C4C186A02F5
523 Interface for adding to ProtocolHandler API
528 const TInt KProtHandlerSessionServerCertUid = 0x1028180D;
529 const TInt KProtHandlerTransactionServerCertUid = 0x1028180E;
531 class MProtHandlerInterface
535 Intended Usage: Get the Server Certificate for the current session.
536 @return The certificate information or NULL if it is not available
538 virtual const CCertificate* SessionServerCert() = 0;
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
545 virtual const CCertificate* TransactionServerCert( RHTTPTransaction aTransaction) = 0;
548 inline void CProtocolHandler::GetInterfaceL(TUid, MProtHandlerInterface*&)
551 inline void CProtocolHandler::Reserved2()
554 #endif // __CPROTOCOLHANDLER_H__