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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // please do not delete
21 @file CProtocolHandler.h
22 @warning : This file contains Rose Model ID comments
25 #ifndef __CPROTOCOLHANDLER_H__
26 #define __CPROTOCOLHANDLER_H__
30 #include <http/framework/httplogger.h>
31 #include <http/mhttpfilter.h>
32 #include <http/rhttpsession.h>
34 // Forward declarations
36 class CProtTransaction;
37 class CSecurityPolicy;
38 class MProtHandlerInterface;
41 The ECom protocol handler plugin interface UID.
45 const TUid KUidProtocolHandlerPluginInterface = {0x1000A449};
49 Defined active object priorities for the Protocol Handler
53 const TInt KProtocolHandlerActivePriority = CActive::EPriorityStandard;
55 Defined active object priorities for the Transaction
59 const TInt KTransactionActivePriority = KProtocolHandlerActivePriority+1;
62 //##ModelId=3C4C186A02A3
63 class CProtocolHandler : public CActive, public MHTTPFilter
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).
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
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).
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
101 @leave KErrNoMemory if there was not enough memory to create the object.
103 //##ModelId=3C4C186B007E
104 static CProtocolHandler* NewL(const TDesC8& aProtocol, RHTTPSession aSession);
107 Intended Usage: Class destructor.
109 //##ModelId=3C4C186B0075
110 IMPORT_C virtual ~CProtocolHandler();
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.
118 //##ModelId=3C4C186B0074
119 IMPORT_C CHeaderCodec* Codec() const;
123 Get the Server Certificate for the current session.
124 @return The certificate information or NULL if it is not available
126 IMPORT_C const CCertificate* SessionServerCert();
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
133 IMPORT_C const CCertificate* TransactionServerCert( RHTTPTransaction aTransaction);
135 public: // Methods to be implemented in specific protocol handlers
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
143 virtual TInt SessionServerCert(TCertInfo& aServerCert) = 0;
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
152 virtual TInt TransactionServerCert(TCertInfo& aServerCert, RHTTPTransaction aTransaction) = 0;
154 public: // Methods from MHTTPFilterBase
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.
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.
166 //##ModelId=3C4C186B0061
167 IMPORT_C virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
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
178 //##ModelId=3C4C186B0057
179 IMPORT_C virtual void MHFSessionRunL(const THTTPSessionEvent& aEvent);
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.
192 //##ModelId=3C4C186B0043
193 IMPORT_C virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
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.
204 //##ModelId=3C4C186B0038
205 IMPORT_C virtual TInt MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent);
207 public: // Methods from MHTTPFilter
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
217 //##ModelId=3C4C186B0025
218 IMPORT_C virtual void MHFUnload(RHTTPSession aSession, THTTPFilterHandle aHandle);
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
228 //##ModelId=3C4C186B001A
229 IMPORT_C virtual void MHFLoad(RHTTPSession aSession, THTTPFilterHandle aHandle);
231 protected: // callbacks/methods for sub-classes
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
240 @param aTrans (in) the completed transaction
241 @param aEventStatus (in) an event to be sent back to the client along
243 @leave THTTPPanic::EInvalidFilterHandle if unable to send event.
245 //##ModelId=3C4C186B0010
246 IMPORT_C void TransactionCompletedL(RHTTPTransaction aTrans, THTTPEvent aEventStatus);
249 Obtain the number of currently active transactions
250 @return The number of currently active transactions
252 //##ModelId=3C4C186B0006
253 IMPORT_C TInt NumActiveTransactions() const;
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
262 //##ModelId=3C4C186A03E5
263 IMPORT_C void TransactionFailed(RHTTPTransaction aTrans);
266 Completes this active object - allows the protocol handler to
267 reevaluate the queue of pending transactions and service new ones
270 //##ModelId=3C4C186A03E4
271 IMPORT_C void CompleteSelf();
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.
283 IMPORT_C TInt FindTransaction(RHTTPTransaction aTransaction, const CProtTransaction*& aProtTransaction) const;
285 private: // methods to be implemented in specific protocol handlers
287 /** Intended usage: Creates the specific type of codec required for a specific type
290 This must be implemented by a concrete protocol handler sub-class.
292 //##ModelId=3C4C186A03DC
293 virtual void CreateCodecL() = 0;
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.
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.
304 @param aTransaction The RHTTPTransaction object associated with
305 this CProtTransaction object.
306 @return A pointer to a created CProtTransaction-derived class.
310 //##ModelId=3C4C186A03DA
311 virtual CProtTransaction* CreateProtTransactionL(RHTTPTransaction aTransaction) = 0;
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
320 This must be implemented by a concrete protocol handler sub-class.
321 @param aTrans The pending protocol transaction object which is to be
323 @return A flag that indicates if the transaction can be serviced immediately.
325 //##ModelId=3C4C186A03D0
326 virtual TBool ServiceL(CProtTransaction& aTrans) = 0;
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.
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.
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.
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.
344 //##ModelId=3C4C186A03C6
345 virtual void ClosedTransactionHook(CProtTransaction* aTrans) = 0;
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.
352 This must be implemented by a concrete protocol handler sub-class.
353 @param aTrans (in) A reference to the transaction being cancelled.
355 //##ModelId=3C4C186A03B3
356 virtual void CancelTransactionHook(CProtTransaction& aTransaction) = 0;
358 /** Intended Usage: Called to notify the concrete protocol handler that new request
359 body data is available for transmission.
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.
365 //##ModelId=3C4C186A03A8
366 virtual void NotifyNewRequestBodyPart(CProtTransaction& aTransaction) = 0;
368 protected: // Methods inherited from CActive
370 /** Intended Usage: Do some processing when a previous asynchronous request made by
371 this object has completed.
373 //##ModelId=3C4C186A0377
374 IMPORT_C virtual void RunL();
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
381 //##ModelId=3C4C186A036E
382 IMPORT_C virtual TInt RunError(TInt aError);
384 /** Intended Usage: Cancel outstanding asynchronous requests that this object has made
386 //##ModelId=3C4C186A036D
387 IMPORT_C virtual void DoCancel();
389 protected: // Methods
392 Constructs a protocol handler associated with the supplied HTTP
394 @param aSession (in) The session on which the new protocol handler will
397 IMPORT_C CProtocolHandler(RHTTPSession aSession);
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
405 //##ModelId=3C4C186A036C
406 IMPORT_C void ConstructL(RHTTPSession aSession);
408 protected: // Attributes
410 /** The session to which this protocol handler is dedicated
412 //##ModelId=3C4C186A033C
413 RHTTPSession iSession;
415 /** The codec used for this protocol handler (to be specialised in subclasses)
417 //##ModelId=3C4C186A032F
418 CHeaderCodec* iCodec;
420 /** HTTP logger handle (debug only)
424 /** An interface providing the security policy. This may be NULL if there is no security policy plugin */
425 //##ModelId=3C4C186A031D
426 CSecurityPolicy* iSecurityPolicy;
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.
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
449 //##ModelId=3C4C186A0362
450 void SubmitTransactionL(RHTTPTransaction aTransaction);
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.
461 //##ModelId=3C4C186A0359
462 void HandleCancelTransaction(RHTTPTransaction aTrans);
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.
471 //##ModelId=3C4C186A034F
472 void HandleClosedTransaction(RHTTPTransaction aTrans);
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.
482 //##ModelId=3C4C186A0346
483 TInt FindTransaction(RHTTPTransaction aTransaction) const;
487 Intended Usage: This is a mechanism for allowing future change to CProtocolHandler API
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)
492 inline virtual void GetInterfaceL(TUid aInterfaceId, MProtHandlerInterface*& aInterfacePtr);
495 /** Intended Usage: Reserve a slot in the v-table to preserve future BC
497 //##ModelId=3C4C186A0344
498 inline virtual void Reserved2();
501 private: // Attributes
503 /** A list of transactions. Each transaction has a list state, e.g. pending,
506 //##ModelId=3C4C186A0313
507 RPointerArray<CProtTransaction> iTransactions;
509 /** The transaction which is currently being serviced - used in RunError so
510 we know which transaction caused RunL to leave.
512 //##ModelId=3C4C186A02FF
513 RHTTPTransaction iCurrentTransaction;
515 /** The destructor key UID indentification required by ECom
517 //##ModelId=3C4C186A02F5
524 Interface for adding to ProtocolHandler API
529 const TInt KProtHandlerSessionServerCertUid = 0x1028180D;
530 const TInt KProtHandlerTransactionServerCertUid = 0x1028180E;
532 class MProtHandlerInterface
536 Intended Usage: Get the Server Certificate for the current session.
537 @return The certificate information or NULL if it is not available
539 virtual const CCertificate* SessionServerCert() = 0;
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
546 virtual const CCertificate* TransactionServerCert( RHTTPTransaction aTransaction) = 0;
549 inline void CProtocolHandler::GetInterfaceL(TUid, MProtHandlerInterface*&)
552 inline void CProtocolHandler::Reserved2()
555 #endif // __CPROTOCOLHANDLER_H__