realtimenetprots/sipfw/SIP/TransactionUser/src/UserAgentServer.h
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:
       
    15 * Name          : UserAgentServer.h
       
    16 * Part of       : TransactionUser
       
    17 * Version       : SIP/5.0
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 /**
       
    25  @internalComponent
       
    26 */
       
    27 
       
    28 #ifndef USERAGENTSERVER_H
       
    29 #define USERAGENTSERVER_H
       
    30 
       
    31 // INCLUDES
       
    32 #include <stringpool.h>
       
    33 
       
    34 #include "MSIPRequestRouterObserver.h"
       
    35 
       
    36 #include "CUserAgent.h"
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class MSIPRequestRouter;
       
    40 class MSipDialogs;
       
    41 class CTimerOwnerResolver;
       
    42 
       
    43 // CLASS DECLARATION
       
    44 
       
    45 class CUserAgentServer :
       
    46 	public CUserAgent,
       
    47 	public MSIPRequestRouterObserver
       
    48 	{
       
    49 public: // Destructor
       
    50 
       
    51 	virtual ~CUserAgentServer();
       
    52 
       
    53 public: // From CUserAgent
       
    54 
       
    55 	TBool IsUAS() const;
       
    56 
       
    57 protected: // From CUserAgent
       
    58 
       
    59 	virtual void CreateTransactionL() = 0;
       
    60 
       
    61 private: // From CUserAgent
       
    62 
       
    63 	TRegistrationId RegistrationId() const;
       
    64 
       
    65 public: // From MSIPRequestRouterObserver
       
    66 
       
    67 	void OwnerFoundL(TUint32 aRequestId, MTransactionOwner* aOwner);
       
    68 
       
    69 	void OwnerNotFoundL(TUint32 aRequestId, CSIPResponse* aResp);
       
    70 
       
    71 	void ErrorOccurred(TUint32 aRequestId, TInt aError);
       
    72 
       
    73 public: // New functions
       
    74 
       
    75 	/**
       
    76 	 * The initial request has been received by the UAS.
       
    77 	 *
       
    78 	 * @pre aReq != NULL
       
    79 	 *
       
    80 	 * @param aReq SIP request received from network. Ownership is transferred.
       
    81 	 * @param aGetTxOwner State the UAS enters if it tries to obtain
       
    82 	 * 	MTranactionOwner.
       
    83 	 * @param aWaitRespFromApp State the UAS enters if the request belongs to
       
    84 	 *	an existing dialog.
       
    85 	 * @param aErrorRespSent State the UAS enters when either Dialog subsystem
       
    86 	 *	or UAS itself decides to send a final response without passing the
       
    87 	 *	request.	 
       
    88 	 */
       
    89 	void InitialRequestReceivedL(CSIPRequest* aReq,
       
    90 								 const CUserAgentState& aGetTxOwner,
       
    91 								 const CUserAgentState& aWaitRespFromApp,
       
    92 								 const CUserAgentState& aErrorRespSent);
       
    93 
       
    94 	/**
       
    95 	 * Callback to upper layer has been obtained. UAS passes the request there
       
    96 	 * and starts waiting for a response.
       
    97 	 *
       
    98 	 * @pre aOwner != NULL
       
    99 	 *
       
   100 	 * @param aOwner Callback to upper layer, ownership isn't transferred
       
   101 	 * @param aWaitRespFromApp State which UAS enters next.	 
       
   102 	 */
       
   103 	void HandleOwnerFoundL(MTransactionOwner* aOwner,
       
   104 						   const CUserAgentState& aWaitRespFromApp);
       
   105 
       
   106 	/**
       
   107 	 * Application to receive the request was not found. Instead a SIP response
       
   108 	 * will be sent to network.
       
   109 	 *
       
   110 	 * @pre aResp != NULL
       
   111 	 *
       
   112 	 * @param aResp Final response. May not be 2xx in case of INVITE.
       
   113 	 *	Ownership is transferred.
       
   114 	 * @param aErrorRespSent State which UAS enters next.	 
       
   115 	 */
       
   116 	void HandleOwnerNotFoundL(CSIPResponse* aResp,
       
   117 							  const CUserAgentState& aFinalRespSent);
       
   118 
       
   119     /**
       
   120 	 * Error occurred during the routing of an incoming SIP request.
       
   121 	 */
       
   122     void RequestRouterErrorL();
       
   123 
       
   124     /**
       
   125 	 * Sends error response to remote endpoint.
       
   126 	 *
       
   127      * @param aErrorRespSent UserAgent enters this state	 
       
   128 	 */
       
   129     void HandleRequestRouterErrorL(const CUserAgentState& aErrorRespSent);
       
   130 
       
   131 	/**
       
   132 	 * Upper layer sends response. UAS checks that response is correct and
       
   133 	 * fills the transaction related headers.
       
   134 	 *
       
   135 	 * @pre aResp != NULL
       
   136 	 *
       
   137 	 * @param aResp SIP response, ownership isn't transferred
       
   138 	 * @param aParam Transport parameters to use when sending the response	 
       
   139 	 */
       
   140 	void HandleSendResponseL(CSIPResponse* aResp,
       
   141 							 const TSIPTransportParams& aParams);
       
   142 
       
   143 	/**
       
   144 	 * Checks that the SIP response message given by upper layer has the
       
   145 	 * required parts filled. If the response isn't ok, function leaves.
       
   146 	 *
       
   147 	 * @param aResp SIP response	 
       
   148 	 */
       
   149 	void CheckResponseL(const CSIPResponse& aResp) const;
       
   150 	
       
   151 	/**
       
   152 	 * Fills the transaction related parts into the SIP response.	 
       
   153 	 *
       
   154 	 * @param aResp IN/OUT: Partially filled SIP response from upper layer.	 
       
   155 	 */
       
   156 	void FillResponseL(CSIPResponse& aResp);
       
   157 
       
   158 	/**
       
   159 	 * Contacts Dialogs subsystem to find out if there is a dialog for the
       
   160 	 * received request
       
   161 	 *
       
   162 	 * @pre iObserver = NULL, iOutgoingMsg = NULL
       
   163 	 *
       
   164 	 * @param aReq Request received from network
       
   165 	 * @return value ETrue: Dialog exists, EFalse: otherwise
       
   166 	 */
       
   167 	TBool DoesDialogExistForRequestL(CSIPRequest& aReq);
       
   168 
       
   169 	/**
       
   170 	 * Pass the SIP response to transaction for sending.
       
   171 	 *
       
   172 	 * @pre iTransaction != NULL, aResp != NULL
       
   173 	 *
       
   174 	 * @param aResp SIP response to send, ownership is transferred.	 
       
   175 	 */
       
   176 	void SendResponseToTransactionL(CSIPResponse* aResp) const;
       
   177 
       
   178 	/**
       
   179 	 * Checks the request received from network is correct.
       
   180 	 *
       
   181 	 * @pre aReasonPhrase != NULL	 
       
   182 	 *
       
   183 	 * @param aReq SIP request received from network
       
   184 	 * @param aResponseCode If function returns EFalse, this parameter will
       
   185 	 *  contain the response code of the response that should be sent back to
       
   186      *  the sender of the invalid request.
       
   187 	 * @param aReasonPhrase If function returns EFalse, this parameter will
       
   188 	 *  have the reason phrase that should be sent back to the sender of the
       
   189 	 *  invalid request.
       
   190 	 * @return value ETrue if the request is ok, EFalse otherwise.	 
       
   191 	 */
       
   192 	TBool CheckReceivedRequest(CSIPRequest& aReq,
       
   193 							   TInt& aResponseCode,
       
   194 							   RStringF& aReasonPhrase) const;
       
   195 
       
   196 	/**
       
   197 	 * Obtains the To tag
       
   198 	 *	 	 
       
   199 	 * @return value To tag
       
   200 	 */
       
   201 	RStringF ToTag() const;
       
   202 
       
   203 protected:
       
   204 
       
   205 	CUserAgentServer(CUserAgentCreateParams& aParams,
       
   206 					 MSipDialogs& aDialogs,
       
   207 					 MSIPRequestRouter& aRouter);	
       
   208 
       
   209 	/**
       
   210 	 * Creates and sends a final response
       
   211 	 *
       
   212 	 * @pre aResponseCode >= 300
       
   213 	 *	 
       
   214 	 * @param aResponseCode Response code to be put into the response
       
   215 	 * @param aReasonPhrase Reason phrase to be put in the response
       
   216 	 * @param aErrorRespSent State which UAS enters after sending the response	 
       
   217 	 */
       
   218 	void SendErrorResponseL(TInt aResponseCode,
       
   219 						    RStringF aReasonPhrase,
       
   220 						    const CUserAgentState& aErrorRespSent);
       
   221 
       
   222     /**
       
   223 	 * Cancels the asynchronous request to obtain MTransactionOwner callback.
       
   224 	 */
       
   225 	void CancelGetOwnerRequest() const;
       
   226 
       
   227     void StopTimerOwnerResolver();
       
   228 
       
   229     /**
       
   230 	 * Store the tag of To-header, if it exists.
       
   231 	 *
       
   232 	 * @pre iToTag.DesC().Length() == 0
       
   233 	 *	 
       
   234 	 * @param aMsg SIP message
       
   235 	 */
       
   236     void StoreToTag(CSIPMessage& aMsg);
       
   237 
       
   238 protected: // Data
       
   239 
       
   240     //Dialog subsystem
       
   241 	MSipDialogs& iDialogs;
       
   242 
       
   243     //Timer specifying how long UAS waits for RequestRouter to provide the
       
   244     //MTransactionOwner of upper layer or an error response. Owned.
       
   245     CTimerOwnerResolver* iTimerOwnerResolver;
       
   246 
       
   247 private:
       
   248 
       
   249 	/**
       
   250 	 * The received request doesn't belong to any dialog
       
   251 	 *
       
   252 	 * @pre aReq != NULL
       
   253 	 *
       
   254 	 * @param aReq SIP request. Ownership is transferred.
       
   255 	 * @param aGetTxOwner State which UAS enters if it contacts AssocMgr for
       
   256 	 *	obtaining MTranactionOwner.
       
   257 	 * @param aErrorRespSent State which UAS enters when either Dialog
       
   258 	 * subsystem or UAS itself decides to send a final response without passing
       
   259 	 *	the request.
       
   260 	 */
       
   261 	void RequestOutsideDialogL(CSIPRequest* aReq,
       
   262 							   const CUserAgentState& aGetTxOwner,
       
   263 							   const CUserAgentState& aErrorRespSent);
       
   264 
       
   265 	/**
       
   266 	 * Fill and send the SIP response got from Dialogs subsystem. The
       
   267 	 * response is located in the send buffer (iOutgoingMsg).
       
   268 	 * Ownership of the response is passed to transaction.
       
   269 	 *
       
   270 	 * @pre iOutgoingMsg != NULL
       
   271 	 * @pre SIP response in iOutgoingMsg must be a 3xx-6xx
       
   272 	 * @post iOutgoingMsg == NULL
       
   273 	 *
       
   274 	 * @param aNextState State where UserAgent moves after sending the response	 
       
   275 	 */
       
   276 	void HandleResponseFromDialogsL(const CUserAgentState& aNextState);
       
   277 
       
   278     /**
       
   279 	 * Send the stored SIP request located in the receive buffer
       
   280      * (iIncomingMsg) to MTransactionOwner.
       
   281 	 *
       
   282 	 * @pre iIncomingMsg != NULL
       
   283 	 * @post iIncomingMsg == NULL	 
       
   284 	 */
       
   285 	void PassStoredRequestToTransactionOwnerL();    
       
   286 
       
   287     /**
       
   288 	 * Start timer determining how long UAS waits for OwnerResolver to
       
   289 	 * return a callback to upper layer.
       
   290      * Timer duration must be shorter than timer F2.
       
   291 	 *
       
   292 	 * @pre iTimerOwnerResolver = NULL
       
   293 	 */
       
   294     void StartTimerOwnerResolverL();
       
   295 
       
   296 private: // Data
       
   297 
       
   298 	//Router which decides where the incoming SIP request will be forwarded.
       
   299 	MSIPRequestRouter& iRouter;
       
   300 
       
   301 	//RequestId received from iRouter
       
   302 	TUint32 iRouterRequestId;
       
   303 
       
   304 	//Tag to be inserted into the To-header of SIP responses
       
   305 	RStringF iToTag;
       
   306 
       
   307 private: // For testing purposes
       
   308 
       
   309 #ifdef CPPUNIT_TEST	
       
   310 	friend class CNormalUAS_GetTxOwner_Test;
       
   311 	friend class CUserAgentServer_Test;
       
   312 	friend class CTransactionUser_Test;
       
   313 #endif
       
   314 
       
   315 	void __DbgTestInvariant() const;
       
   316 
       
   317 	};
       
   318 
       
   319 #endif // end of USERAGENTSERVER_H
       
   320 
       
   321 // End of File