LibSip_Steps.ttcn 144 KB
Newer Older
	}// end function f_setHeadersGeneral
	
poglitsch's avatar
poglitsch committed


	/**
		* 
		* @desc function for setting of component variables related to message header fields 
		*		(message type independent: CSeq, contact, via), function uses information from userprofile
		*		
		* @param p_cSeq_s CSeq parameter
		* @param p_method method name for cSeq header field
		*/	
		function f_setHeadersACK() runs on SipComponent
    	{
			// vc_requestUri.hostPort := vc_reqHostPort;
    		if(vc_response.statusLine.statusCode >= 200 and vc_response.statusLine.statusCode <= 299 ) //ref. RFC3261 8.1.1.7 Via
			{
				vc_branch := c_branchCookie & f_getRndTag();
			}
poglitsch's avatar
poglitsch committed
			vc_via:={
        		fieldName := VIA_E,
        		viaBody 	 := {valueof(m_ViaBody_currIpaddr(vc_branch, vc_userprofile))}
			};
    	}// end function f_setHeadersGeneral
	
	/**
	 * 
	 * @desc setting of general and basic Bye header fields
	 * 		in additon to the addresses (To, From, ReqUri)
	 * @param p_cSeq_s
	 */
	function f_setHeadersBYE(inout CSeq p_cSeq_s) runs on SipComponent
	{      
	  f_setHeadersGeneral(p_cSeq_s, "BYE"); // cseq, contact, branch, via

poglitsch's avatar
poglitsch committed
	  //vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

	  f_addTagInTo(vc_to);

	  vc_cancel_To := vc_to;
	  vc_caller_To := vc_to;
      
	  vc_caller_From := vc_from;
poglitsch's avatar
poglitsch committed
           
	  vc_reqHostPort := vc_requestUri.components.sip.hostPort;
      
	}// end function f_setHeadersBYE
	
	/**
	 * 
	 * @desc setting of general and basic CANCEL header fields
	 * @param p_cSeq_s
	 */
	function f_setHeadersCANCEL(inout CSeq p_cSeq_s) runs on SipComponent
	{      

		p_cSeq_s.method := "CANCEL"; 
		//vc_branch := c_branchCookie & f_getRndTag(); // STF 406: CANCEL and ACK should have the same branch as the INVITE
		vc_via:={
    				fieldName := VIA_E,
    				viaBody 	 := {valueof(m_ViaBody_currIpaddr(vc_branch, vc_userprofile))}
		};		
	}// end function f_setHeadersCANCEL
	 * 
	 * @desc function sets header field for the next outgoing REGISTER message
	 * @param p_cSeq_s CSeq parameter to be applied
	 */
garciay's avatar
garciay committed
 	function f_setHeaders_REGISTER(inout CSeq p_cSeq_s, boolean p_emergency:=false) runs on SipComponent
	{
	  var SemicolonParam_List v_params;

	  f_setHeadersGeneral(p_cSeq_s, "REGISTER"); // cseq, contact, branch, via

	  vc_requestUri:=
	  {
		scheme := c_sipScheme,
        components := {sip:={
		hostPort := {host:=vc_userprofile.registrarDomain, portField:=omit}}},
		urlParameters := omit,
		headers := omit
	  };
      
	  vc_reqHostPort := vc_requestUri.components.sip.hostPort;
	  vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };
	  vc_callIdReg := vc_callId; //remember callId for de-registration
 
      
	  vc_to := valueof(m_To(m_SipUrl_currDomain(vc_userprofile)));
	  vc_cancel_To := vc_to;
	  v_params := {{id:=c_tagId, paramValue:=f_getRndTag()}}
	  vc_from := {fieldName := FROM_E,
		addressField :=vc_to.addressField,
		fromParams := v_params
	  };
	  
	  if(not vc_firstREGISTER_sent)
	  {
garciay's avatar
garciay committed
		  if (p_emergency) {
		      v_params := { { "sos", omit } };
			  vc_contact.contactBody.contactAddresses[0].addressField.addrSpecUnion.urlParameters := v_params;
		  } else {
			  v_params := { {id:=c_expiresId, paramValue:=c_shortRegistration} };
			  vc_contact.contactBody.contactAddresses[0].contactParams := v_params;
		  }
	  }
	  
	  vc_firstREGISTER_sent := true;//f_setHeaders_Register is called in deREGISTER function
	  
	  vc_authorization := 
	  {
		fieldName := AUTHORIZATION_E,
		body := {f_calculatecCredentials_empty(vc_userprofile)}
	}// end function setHeaders_REGISTER

	/**
	 * 
	 * @desc function sets via, cseq and authorization header for the next outgoing (protected) REGISTER
 	function f_setHeaders_2ndREGISTER(inout CSeq p_cSeq_s) runs on SipComponent
	{
	  var CommaParam_List v_challenge;
	  
	  //Increment CSeq sequence number 
	  p_cSeq_s.seqNumber := p_cSeq_s.seqNumber + 1;
	  vc_cSeq := p_cSeq_s;
poglitsch's avatar
poglitsch committed
	  
		vc_requestUri:=
    	{
            scheme := c_sipScheme,
            components := {sip:={
poglitsch's avatar
poglitsch committed
            userInfo := omit,
            hostPort := {host:=vc_userprofile.registrarDomain, portField:=omit}}},
poglitsch's avatar
poglitsch committed
            urlParameters := omit,
            headers := omit
    	};
	  //new branch tag due to different branch tag in new REGISTER method
	  vc_branch := c_branchCookie & f_getRndTag();

	  vc_via_REG :={
		fieldName := VIA_E,
		viaBody 	 := {valueof(m_ViaBody_currIpaddr(vc_branch, vc_userprofile))}
	  };
	  
	  // Extract challenge and calculate credentials for a response.
	  v_challenge := vc_response.msgHeader.wwwAuthenticate.challenge.digestCln;
      // Prepair right answer      
	  vc_authorization := 
		   {
			 fieldName := AUTHORIZATION_E,
			 body := {f_calculatecCredentials(vc_userprofile, "REGISTER", v_challenge)}
		   }
				
	}// end function f_setHeaders_2ndREGISTER

	/**
	 * 
	 * @desc function sets via, cseq and authorization header for the next outgoing (protected) REGISTER
	 * NO response in Authorization header to cause an error
	 * @verdict 
	 */
	function f_setHeaders_2ndREGISTER_wo_response() runs on SipComponent
	{
	  var CommaParam_List v_challenge;
		
	  vc_branch := c_branchCookie & f_getRndTag();

	  vc_via_REG :={
		fieldName := VIA_E,
		viaBody 	 := {valueof(m_ViaBody_currIpaddr(vc_branch, vc_userprofile))}
	  };
	  
	  if(ischosen(vc_response.msgHeader.wwwAuthenticate.challenge.otherChallenge))
	  // Extract challenge and calculate credentials for a response.
	  {
	  	v_challenge := vc_response.msgHeader.wwwAuthenticate.challenge.otherChallenge.authParams;
	  }
	  else
	  {
	  	v_challenge := vc_response.msgHeader.wwwAuthenticate.challenge.digestCln;
	  }
	  
	  // Increment CSeq sequence number 
	  vc_cSeq.seqNumber := vc_cSeq.seqNumber + 1;
      
	  // Prepair right answer      
	  vc_authorization := 
		   {
			 fieldName := AUTHORIZATION_E,
			 body := {f_calculatecCredentials_wo_response(vc_userprofile, "REGISTER", v_challenge)}
		   }
				
	}// end function f_setHeaders_2ndREGISTER_wo_response

	/**
	 * 
	 * @desc function sets via, cseq and authorization header with different private name for the next outgoing (protected) REGISTER
	 * @verdict 
	 */
 	function f_setHeaders_2ndREGISTER_authorizationWithDifferentUserName() runs on SipComponent
	{
	  var CommaParam_List v_challenge;
		
	  vc_branch := c_branchCookie & f_getRndTag();
poglitsch's avatar
poglitsch committed
	  
		vc_requestUri:=
		{
			scheme := c_sipScheme,
            components := {sip:={
poglitsch's avatar
poglitsch committed
			userInfo := omit,
			hostPort := {host:=vc_userprofile.registrarDomain, portField:=omit}}},
poglitsch's avatar
poglitsch committed
			urlParameters := omit,
			headers := omit
		};

	  vc_via_REG :={
		fieldName := VIA_E,
		viaBody 	 := {valueof(m_ViaBody_currIpaddr(vc_branch, vc_userprofile))}
	  };
	  
	  // Extract challenge and calculate credentials for a response.
	  v_challenge := vc_response.msgHeader.wwwAuthenticate.challenge.otherChallenge.authParams;
	            
	  // Increment CSeq sequence number 
	  vc_cSeq.seqNumber := vc_cSeq.seqNumber + 1;
      
      // Prepair right answer      
	  vc_authorization := 
		   {
			 fieldName := AUTHORIZATION_E,
			 body := {f_calculatecCredentialsAndChangeUserName(vc_userprofile, "REGISTER", v_challenge)}
		   }
				
	}// end function f_setHeaders_2ndREGISTER_authorizationWithDifferentUserName


	/**
	 * 
	 * @desc function sets header fields for the next outgoing REGISTER (de-registration)
	 * @param p_cSeq_s cSeq to be used
	 * @verdict 
	 */
 	function f_setHeaders_deREGISTER(inout CSeq p_cSeq_s) runs on SipComponent
	{
    	var SemicolonParam_List v_params;
    	
    	f_setHeadersGeneral(p_cSeq_s, "REGISTER"); // cseq, contact, branch, via
    	
		vc_requestUri:=
			scheme := c_sipScheme,
            components := {sip:={
    		userInfo := omit,
    		hostPort := {host:=vc_userprofile.registrarDomain, portField:=omit}}},
    		urlParameters := omit,
    		headers := omit
    	vc_to := valueof(m_To(m_SipUrl_currDomain(vc_userprofile)));
    	v_params := {{id:=c_tagId, paramValue:=f_getRndTag()}}
    	vc_from := {fieldName := FROM_E,
            addressField :=vc_to.addressField,
            fromParams := v_params
    	};
    	
        vc_via_REG :={
          fieldName := VIA_E,
          viaBody 	 := {valueof(m_ViaBody_currIpaddr(vc_branch, vc_userprofile))}
        };
    	
    	//set of empty authorization header to avoid setting of different values of nonce count and response
        vc_authorization := 
        {
          fieldName := AUTHORIZATION_E,
          body := {f_calculatecCredentials_empty(vc_userprofile)}
        }
    	
    	//TODO: delete 2nd solution of deregistration when other is working
        vc_contact.contactBody.contactAddresses[0].contactParams := {{"expires","0"}};
//    	TODO: 1st solution of deRegistration: Cancelation of Registration due to RFC3665/2.4
//    	vc_contact := 
//    		{
//    		  fieldName := CONTACT_E,
//    		  contactBody := {wildcard := "*" } 
//    		};



	} // end function f_setHeaders_deREGISTER


	/**
	 * @desc setting of general and basic Invite header fields
	 * 		in additon to the addresses (To, From, ReqUri)
	 * @param p_cSeq_s
	 */
	function f_setHeadersINVITE(inout CSeq p_cSeq_s) runs on SipComponent
	{      
	  f_setHeadersGeneral(p_cSeq_s, "INVITE"); // cseq, contact, branch, via

	  vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

	  vc_cancel_To := vc_to;
	  vc_caller_To := vc_to;
      
	  vc_caller_From := vc_from;
garciay's avatar
garciay committed

      if (ischosen(vc_requestUri.components.sip)) { // sip/sips call
        vc_reqHostPort := vc_requestUri.components.sip.hostPort;
      } else if (ischosen(vc_requestUri.components.urn)) { // Emergency call
        vc_reqUrnUri := vc_requestUri.components.urn;
      } else {
        log ("f_setHeadersINVITE: unsupported field: ", vc_requestUri);
        setverdict(fail);
      } 
      
	}// end function f_setHeadersINVITE
poglitsch's avatar
poglitsch committed
	
	/**
	* 
	* @desc setting of general and basic Update header fields
	* 		in additon to the addresses (To, From, ReqUri)
	* @param p_cSeq_s
	*/
	function f_setHeadersUPDATE(inout CSeq p_cSeq_s) runs on SipComponent
	{      
			f_setHeadersGeneral(p_cSeq_s, "UPDATE"); // cseq, contact, branch, via

			vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

			vc_cancel_To := vc_to;
			vc_caller_To := vc_to;
  
			vc_caller_From := vc_from;
        
			vc_reqHostPort := vc_requestUri.components.sip.hostPort;
poglitsch's avatar
poglitsch committed
  
	}// end function f_setHeadersUPDATE

	/**
	 * 
	 * @desc setting of general and basic Message header fields
	 * 		in additon to the addresses (To, From, ReqUri)
	 * @param p_cSeq_s
	 */
	function f_setHeadersMESSAGE(inout CSeq p_cSeq_s) runs on SipComponent
	{      
	  f_setHeadersGeneral(p_cSeq_s, "MESSAGE"); // cseq, contact, branch, via

	  vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

	  vc_cancel_To := vc_to;
	  vc_caller_To := vc_to;
      
	  vc_caller_From := vc_from;
            
	  vc_reqHostPort := vc_requestUri.components.sip.hostPort;
      
	}// end function f_setHeadersMESSAGE

rennoch's avatar
rennoch committed
	/**
		* 
		* @desc setting of general and basic Notify header fields
		* 		in additon to the addresses (To, From, ReqUri)
		* @param p_cSeq_s
		*/
	function f_setHeadersNOTIFY(inout CSeq p_cSeq_s) runs on SipComponent
	{      
			f_setHeadersGeneral(p_cSeq_s, "NOTIFY"); // cseq, contact, branch, via
rennoch's avatar
rennoch committed
			vc_cancel_To := vc_to;
			vc_caller_To := vc_to;
			vc_caller_From := vc_from;
            
			vc_reqHostPort := vc_requestUri.components.sip.hostPort;
rennoch's avatar
rennoch committed
      
	}// end function f_setHeadersNOTIFY

	/**
		* 
		* @desc setting of general and basic Publish header fields
		* 		in additon to the addresses (To, From, ReqUri)
		* @param p_cSeq_s
		*/
	function f_setHeadersPUBLISH(inout CSeq p_cSeq_s) runs on SipComponent
	{      
			f_setHeadersGeneral(p_cSeq_s, "PUBLISH"); // cseq, contact, branch, via
			
			//after SUBSCRIBE message callid shall be same
			//vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

			vc_cancel_To := vc_to;
			vc_caller_To := vc_to;
      
			vc_caller_From := vc_from;
            
			vc_reqHostPort := vc_requestUri.components.sip.hostPort;
      
	}// end function f_setHeadersPUBLISH

	/**
	 * 
	 * @desc function sets header field for the next outgoing SUBSCRIBE message
	 * @param p_cSeq_s CSeq parameter to be applied
	 */
 	function f_setHeaders_SUBSCRIBE(inout CSeq p_cSeq_s) runs on SipComponent
	{
	  var SemicolonParam_List v_params;
	  
	  f_setHeadersGeneral(p_cSeq_s, "SUBSCRIBE"); // cseq, contact, branch, via
  
  	  vc_requestUri:=valueof(m_SipUrl_currDomain(vc_userprofile));
  	  
	  vc_reqHostPort := vc_requestUri.components.sip.hostPort;
berge's avatar
berge committed
	  vc_callId := {
		fieldName := CALL_ID_E,
		callid := f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr
	  }
      
	  vc_to := valueof(m_To(m_SipUrl_currDomain(vc_userprofile)));
	  vc_cancel_To := vc_to;
	  v_params := {{id := c_tagId, paramValue := f_getRndTag()}};
berge's avatar
berge committed
	  vc_from := {
		fieldName := FROM_E,
		addressField := vc_to.addressField,
		fromParams := v_params
      
	}// end function setHeaders_SUBSCRIBE
	/**
		* 
		* @desc setting of general and basic Subscribe header fields
		* 		in additon to the addresses (To, From, ReqUri)
		* @param p_cSeq_s
		*/
	function f_setHeadersSUBSCRIBE(inout CSeq p_cSeq_s) runs on SipComponent
	{      
			f_setHeadersGeneral(p_cSeq_s, "SUBSCRIBE"); // cseq, contact, branch, via

			vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

			vc_cancel_To := vc_to;
			vc_caller_To := vc_to;
      
			vc_caller_From := vc_from;
            
			vc_reqHostPort := vc_requestUri.components.sip.hostPort;
      
	}// end function f_setHeadersMESSAGE
	
	/**
	 * 
	 * @desc setting of general and basic REFER header fields
	 * 		in additon to the addresses (To, From, ReqUri)
	 * @param p_cSeq_s
	 */
	function f_setHeadersREFER(inout CSeq p_cSeq_s) runs on SipComponent
	{      
	  f_setHeadersGeneral(p_cSeq_s, "REFER"); // cseq, contact, branch, via

juvancic's avatar
juvancic committed
	  //vc_callId := { fieldName:=CALL_ID_E, callid:=f_getRndCallId(p_cSeq_s) & c_AT & vc_userprofile.currIpaddr };

	  vc_cancel_To := vc_to;
	  vc_caller_To := vc_to;
      
	  vc_caller_From := vc_from;
            
	  vc_reqHostPort := vc_requestUri.components.sip.hostPort;
      
	}// end function f_setHeadersREFER
	 * 
	 * @desc This function reads all necessary headers from the received REGISTER message and generate the tag for the answer
	 * @param p_Request REGISTER that has been received
	 */
	function f_setHeadersOnReceiptOfREGISTER(Request p_Request)
	runs on SipComponent {

	  f_setHeadersOnReceiptOfRequest(p_Request);
	
	  vc_callId := p_Request.msgHeader.callId;
	  vc_caller_From := vc_from;
	  f_addTagInTo(vc_to);
	  vc_caller_To := vc_to;
	  vc_requestUri := p_Request.requestLine.requestUri;
      
	  vc_cancel_To := p_Request.msgHeader.toField;
      
	  if (ispresent(p_Request.msgHeader.contact) and (not ischosen(p_Request.msgHeader.contact.contactBody.wildcard))) {
		vc_reqHostPort := f_getContactAddr(p_Request.msgHeader.contact.contactBody.contactAddresses[0]);
	  	}
      
	  // update callee information and pick up tag if the call need to be canceled
	  vc_callee_To := {fieldName := TO_E,
		addressField := vc_caller_From.addressField,
		toParams := vc_caller_From.fromParams};
      
	  vc_callee_From := {fieldName := FROM_E,
		addressField := vc_caller_To.addressField,
		fromParams := vc_caller_To.toParams};

	  if (ispresent(p_Request.msgHeader.authorization)) {
		vc_authorization := p_Request.msgHeader.authorization;
	    };
      
	} // end f_setHeadersOnReceiptOfREGISTER

	/**
	 * 
	 * @desc This function reads all necessary headers from the received SUBSCRIBE message and generate the tag for the answer
	 * @param p_Request SUBSCRIBE that has been received
	 */
	function f_setHeadersOnReceiptOfSUBSCRIBE(Request p_Request)
	runs on SipComponent {

	  f_setHeadersOnReceiptOfRequest(p_Request);
	
	  vc_callId := p_Request.msgHeader.callId;
	  vc_caller_From := vc_from;
	  f_addTagInTo(vc_to);
	  vc_caller_To := vc_to;
	  vc_requestUri := p_Request.requestLine.requestUri;
      
	  vc_cancel_To := p_Request.msgHeader.toField;
      
	  if (ispresent(p_Request.msgHeader.contact)) {
		vc_reqHostPort := f_getContactAddr(p_Request.msgHeader.contact.contactBody.contactAddresses[0]);
		}
      
	  // update callee information and pick up tag if the call need to be canceled
	  vc_callee_To := {fieldName := TO_E,
		addressField := vc_caller_From.addressField,
		toParams := vc_caller_From.fromParams};
      
	  vc_callee_From := {fieldName := FROM_E,
		addressField := vc_caller_To.addressField,
		fromParams := vc_caller_To.toParams};
      
	} // end f_setHeadersOnReceiptOfSUBSCRIBE
	
    function f_setHeadersOnReceiptOfREFER(Request p_Request)
    runs on SipComponent {

      f_setHeadersOnReceiptOfRequest(p_Request);
	
      vc_requestUri := p_Request.requestLine.requestUri;
      vc_cancel_To := p_Request.msgHeader.toField;
      
      if (ispresent(p_Request.msgHeader.contact)) {
        vc_reqHostPort := f_getContactAddr(p_Request.msgHeader.contact.contactBody.contactAddresses[0]);
        vc_requestUri := f_getContactUri(p_Request.msgHeader.contact.contactBody.contactAddresses[0]);
        }
      
      // update callee information and pick up tag if the call need to be canceled
      vc_callee_To := {fieldName := TO_E,
        addressField := vc_caller_From.addressField,
        toParams := vc_caller_From.fromParams};
      
      vc_callee_From := {fieldName := FROM_E,
        addressField := vc_caller_To.addressField,
        fromParams := vc_caller_To.toParams};
      
    } // end f_setHeadersOnReceiptOfSUBSCRIBE
	 * @desc function reads all necessary headers from 
	 * the received INVITE message and generate the tag for the answer
	 * @param p_Request received INVITE message
	 * @verdict 
	 */
	function f_setHeadersOnReceiptOfINVITE(Request p_Request) runs on SipComponent {

	f_setHeadersOnReceiptOfRequest(p_Request);

	vc_callId := p_Request.msgHeader.callId;

poglitsch's avatar
poglitsch committed
	vc_requestUri2 := p_Request.requestLine.requestUri;
      
	vc_cancel_To := p_Request.msgHeader.toField;
	f_addTagInTo(vc_to);
	vc_caller_From := vc_from;
	vc_caller_To := vc_to;
      
	if (ispresent(p_Request.msgHeader.contact)) {
	   	vc_reqHostPort := 
	  	f_getContactAddr(p_Request.msgHeader.contact.contactBody.contactAddresses[0]);
poglitsch's avatar
poglitsch committed
		vc_requestUri := f_getContactUri(p_Request.msgHeader.contact.contactBody.contactAddresses[0]);
 	};
      
	 // update callee information and pick up tag if the call need to be canceled
	vc_callee_To := {fieldName := TO_E,
	   addressField := vc_caller_From.addressField,
	   toParams := vc_caller_From.fromParams};
      
	vc_callee_From := {fieldName := FROM_E,
	   addressField := vc_caller_To.addressField,
	   fromParams := vc_caller_To.toParams};
        
	if (ispresent(p_Request.msgHeader.privacy)) {
		vc_privacy := p_Request.msgHeader.privacy;
		};
        
	if (ispresent(p_Request.messageBody)) { 
		//cleaning of attributes before assignment
		if (ispresent(vc_sdp_remote.media_list))
		{
poglitsch's avatar
poglitsch committed
			var integer v_length := sizeof(vc_sdp_remote.media_list);
			for (var integer i:=0; i<v_length; i:=i+1)
			{			
				if (ispresent(vc_sdp_remote.media_list[i].attributes))
				{
reinaortega's avatar
reinaortega committed
					vc_sdp_remote.media_list[i].attributes := omit ; 
poglitsch's avatar
poglitsch committed
				}
			};
		}		
		
		// save SDP if present
		if ( ischosen(p_Request.messageBody.sdpMessageBody)) 
		{
			vc_sdp_remote := p_Request.messageBody.sdpMessageBody;		  
			vc_sdp_remote_is_valid := true;
   			f_prepare_SDP_answer();			 			
		};
		
		// save XML if present
		if ( ischosen(p_Request.messageBody.xmlBody))
		{
			vc_xml_remote := p_Request.messageBody.xmlBody;		 			
		}

		if ( ischosen(p_Request.messageBody.mimeMessageBody))
		{
			
			for (var integer j:=0; j<sizeof(p_Request.messageBody.mimeMessageBody.mimeEncapsulatedList); j:=j+1){
				if (match(p_Request.messageBody.mimeMessageBody.mimeEncapsulatedList[j].content_type,c_sdpAplication))
				{
					vc_sdp_remote := p_Request.messageBody.mimeMessageBody.mimeEncapsulatedList[j].mime_encapsulated_part.sdpMessageBody;
					vc_sdp_remote_is_valid := true;
					f_prepare_SDP_answer();
				};
				if (match(p_Request.messageBody.mimeMessageBody.mimeEncapsulatedList[j].content_type,c_xmlAplication))
				{
					vc_xml_remote := p_Request.messageBody.mimeMessageBody.mimeEncapsulatedList[j].mime_encapsulated_part.xmlBody;
				};			
			}	
		}	
	};
	   
	if (ispresent(p_Request.msgHeader.supported.optionsTags)) {
		for (var integer i := sizeof(p_Request.msgHeader.supported.optionsTags); i>0; i:=i-1)
		   {
			   if (p_Request.msgHeader.supported.optionsTags[i-1]=="100rel")
			   { vc_supported_100rel := true };
			   if (p_Request.msgHeader.supported.optionsTags[i-1]=="precondition")
			   { vc_supported_precondition := true }
		   }
	   	};
      
   } // end f_setHeadersOnReceiptOfINVITE

	/**
	 * 
	 * @desc function reads header field of a received BYE message 
	 * @param p_Request received BYE
	 */
   function f_setHeadersOnReceiptOfBYE(Request p_BYE_Request)
   runs on SipComponent
   {
   	
	 f_setHeadersOnReceiptOfRequest(p_BYE_Request);
	 vc_callId := p_BYE_Request.msgHeader.callId;

   } // end f_setHeadersOnReceiptOfBYE

	/**
	 * 
	 * @desc function reads header field from an incoming Request message
	 * @param p_Request received Request message
	 */
	function f_setHeadersOnReceiptOfRequest(Request p_Request) runs on SipComponent {
     vc_request := p_Request;
     vc_callId := p_Request.msgHeader.callId;
	 vc_cSeq := p_Request.msgHeader.cSeq;
	 vc_iut_CSeq  := p_Request.msgHeader.cSeq;
	 vc_from := p_Request.msgHeader.fromField;
	 vc_caller_From := p_Request.msgHeader.fromField;
	 vc_to := p_Request.msgHeader.toField;
	 vc_caller_To := p_Request.msgHeader.toField;
	 vc_via := p_Request.msgHeader.via;
	 // update sent_label according to received via header field
	 f_getViaReplyAddr(vc_via.viaBody, vc_sent_label);
	  
	 // Catch route
	 vc_boo_recordRoute:=false;
	  
	 //add tag field into To header if tag is not present
	 if (not(ispresent(p_Request.msgHeader.toField.toParams)))
	 {
		vc_to.toParams := {{id := c_tagId, paramValue := f_getRndTag()}};
		vc_caller_To := vc_to;
	 }
	 if (ispresent(p_Request.msgHeader.recordRoute))
	 {
	   vc_boo_recordRoute:=true;
	   vc_recordRoute := p_Request.msgHeader.recordRoute;
	 }
     if (ispresent(p_Request.msgHeader.route))
     {
       //used in case when route header is received (isc interface)
       vc_route := p_Request.msgHeader.route;
     }
   	} // end f_setHeadersOnReceiptOfRequest

	/**
	 * 
	 * @desc functions reads header fields from an incoming Response message
	 * @param p_cSeq
	 * @param p_response received response message
	 * @verdict 
	 */
    function f_setHeadersOnReceiptOfResponse(inout CSeq p_cSeq, Response p_response) runs on SipComponent
   {
	 var integer v_i, v_j, v_nbroute;
	 var Contact v_contact; //only for local purpose
	       
	 vc_response := p_response;
	 //vc_cSeq := p_cSeq; //must not save global c_seq because it can overwrite temporary cSeq
	 vc_to :=p_response.msgHeader.toField;
	 vc_from :=p_response.msgHeader.fromField;
	 vc_caller_To := vc_to;
	 vc_caller_From := vc_from;
      
	 if (ispresent(p_response.msgHeader.contact))
	 {
	   v_contact := p_response.msgHeader.contact;
	   if (ischosen(v_contact.contactBody.contactAddresses))
	   {
		 vc_reqHostPort := f_getContactAddr(v_contact.contactBody.contactAddresses[0]);
poglitsch's avatar
poglitsch committed
		 vc_requestUri := f_getContactUri(v_contact.contactBody.contactAddresses[0]);
	   }
	 }
	 else
	 {
	   if (ischosen(vc_to.addressField.nameAddr))
	   {
           if (ischosen(vc_to.addressField.nameAddr.addrSpec.components.sip))
           {
    		 vc_reqHostPort := vc_to.addressField.nameAddr.addrSpec.components.sip.hostPort;
    		 vc_requestUri := vc_to.addressField.nameAddr.addrSpec;
           }
garciay's avatar
garciay committed
	     if (ischosen(vc_to.addressField.addrSpecUnion.components.sip)) { // sip/sips call
		   vc_reqHostPort := vc_to.addressField.addrSpecUnion.components.sip.hostPort;
	     } else if (ischosen(vc_to.addressField.addrSpecUnion.components.urn)) { // Emergency call
		   vc_reqUrnUri := vc_to.addressField.addrSpecUnion.components.urn;
	     } else {
	       log ("f_setHeadersOnReceiptOfResponse: unsupported field: ", vc_to);
	       setverdict(fail);
	     }
		 vc_requestUri := vc_to.addressField.addrSpecUnion;
poglitsch's avatar
poglitsch committed
	 
	 vc_callee_To:={fieldName := TO_E,
	   addressField := vc_caller_From.addressField,
	   toParams := vc_caller_From.fromParams};
      
	 vc_callee_From:= {fieldName := FROM_E,
	   addressField := vc_caller_To.addressField,
	   fromParams := vc_caller_To.toParams};
	 
	 vc_via:= p_response.msgHeader.via;
      
	 // Route Management
	 if (ispresent(p_response.msgHeader.recordRoute))
	 {
	   vc_recordRoute := p_response.msgHeader.recordRoute;
	   v_nbroute := sizeof(vc_recordRoute.routeBody);
	   // copy and reverse the order of the routes in route header
	   for (v_i:=0; v_i<=(v_nbroute - 1); v_i:=v_i+1)
	   {
		 v_j:= v_nbroute - 1 - v_i;
		 vc_route.routeBody[v_j]:=vc_recordRoute.routeBody[v_i];
	   }
	   vc_route.fieldName := ROUTE_E;
	   vc_boo_recordRoute := true;
	   vc_boo_route := true;
	 }
	 else
	 {
	   vc_boo_recordRoute := false;
	   vc_boo_route := false;
	 };


	 // extentions due to new fields in PRACK and UPDATE messages
	 if (ispresent(p_response.msgHeader.rSeq)) {
	 	vc_rAck := 
			 { fieldName := RACK_E, 
			   responseNum := valueof(p_response.msgHeader.rSeq.responseNum),
			   seqNumber := valueof(p_response.msgHeader.cSeq.seqNumber),
			   method := valueof(p_response.msgHeader.cSeq.method)
			 };
		 };

	 // extentions due to new HistoryInfo fields 180 or 200OK messages
	 if (ispresent(p_response.msgHeader.historyInfo)) {
	 	vc_historyInfoList := valueof(p_response.msgHeader.historyInfo.historyInfoList);
		vc_history_is_valid := true
		}
	   else {vc_history_is_valid := false};

	 //sdpMessageBody answer
	 if (ispresent(p_response.messageBody)) { 
		if ( ischosen(p_response.messageBody.sdpMessageBody))
		{
			vc_sdp_remote := p_response.messageBody.sdpMessageBody;		  
			vc_sdp_remote_is_valid := true;
	 	}

		if ( ischosen(p_response.messageBody.xmlBody))
		{
			vc_xml_remote := p_response.messageBody.xmlBody;		 			
		}

		if ( ischosen(p_response.messageBody.mimeMessageBody))
		{
			
			for (var integer j:=0; j<sizeof(p_response.messageBody.mimeMessageBody.mimeEncapsulatedList); j:=j+1){
				if (match(p_response.messageBody.mimeMessageBody.mimeEncapsulatedList[j].content_type,c_sdpAplication))
				{
					vc_sdp_remote := p_response.messageBody.mimeMessageBody.mimeEncapsulatedList[j].mime_encapsulated_part.sdpMessageBody;
				};
				if (match(p_response.messageBody.mimeMessageBody.mimeEncapsulatedList[j].content_type,c_xmlAplication))
				{
					vc_xml_remote := p_response.messageBody.mimeMessageBody.mimeEncapsulatedList[j].mime_encapsulated_part.xmlBody;
				};			
			}	
		}
	 };

   }// end function f_setHeadersOnReceiptOfResponse

   /**
	* 
	* @desc functions reads ServiceRoute header field from an incoming 200 Response message in registration
	* @param p_cSeq
	* @param p_response received response message
	*/
    function f_getServiceRouteMapIntoRouteInRegistration(inout CSeq p_cSeq, Response p_response) runs on SipComponent
   {
	 var integer v_i, v_j, v_nbroute;
	 var ServiceRoute v_serviceRoute;
	       
	 // Route Management
	 if (ispresent(p_response.msgHeader.serviceRoute))
	 {
	   v_serviceRoute := p_response.msgHeader.serviceRoute;
	   v_nbroute := sizeof(v_serviceRoute.routeBody);
	   // copy and reverse the order of the routes in route header
	   for (v_i:=0; v_i<=(v_nbroute - 1); v_i:=v_i+1)
	   {
		 v_j:= v_nbroute - 1 - v_i;
		 vc_route.routeBody[v_j]:=v_serviceRoute.routeBody[v_i];
	   }
	   vc_route.fieldName := ROUTE_E;
   	   vc_route_REG := vc_route;
	   vc_boo_route := true;
	 }

   }// end function f_getServiceRouteMapIntoRouteInRegistration

   /**
	* 
	* @desc functions reads Route header field from an incoming Request message and generate RecordRoute
	* @param p_cSeq
	* @param p_request received request message
	*/
    function f_getRouteMapIntoRecordRoute(inout CSeq p_cSeq, Request p_request) runs on SipComponent
   {
	 var integer v_i, v_j, v_nbroute;
	 var Route v_route;
	       
	 // Route Management
	 if (ispresent(p_request.msgHeader.route))
	 {
	   v_route := p_request.msgHeader.route;
	   v_nbroute := sizeof(v_route.routeBody);
	   // copy and reverse the order of the routes in route header
	   for (v_i:=0; v_i<=(v_nbroute - 1); v_i:=v_i+1)
	   {
		 v_j:= v_nbroute - 1 - v_i;
		 vc_recordRoute.routeBody[v_j]:=v_route.routeBody[v_i];
	   }
berge's avatar
berge committed
	   vc_recordRoute.fieldName := RECORD_ROUTE_E;
	   
	   vc_boo_recordRoute := true;
	 }

   }// end function f_getRouteMapIntoRecordRoute


} // end group SetHeaders
   
} // end group FieldOperations

group SDPOperations{
	
	/** 
	*  @desc check if message body include SDP attribute (2nd parameter)
	*        for any media 
	*		 
	*/
	function f_check_attribute(in SDP_Message p_sdp, in template SDP_attribute p_attribute) runs on SipComponent return boolean {
		
    	if (ispresent(p_sdp.media_list)) {
    		for (var integer j:=0; j<sizeof(p_sdp.media_list); j:=j+1){			
    			if (ispresent(p_sdp.media_list[j].attributes)) {
    				for (var integer i:=0; i<sizeof(p_sdp.media_list[j].attributes); i:=i+1){			
    					if (match(p_sdp.media_list[j].attributes[i],p_attribute)) 
    						{return(true);};
    					};
    			}
    			};
    	}
    	if (ispresent(p_sdp.attributes)) {
    		for (var integer j:=0; j<sizeof(p_sdp.attributes); j:=j+1){			
    			if (match(p_sdp.attributes[j],p_attribute)) {return(true);};
    			};
    	}
    	
    	return(false);
	}		
    /** 
    *  @desc check if message body include SDP (session level) attribute (2nd parameter)
    *        for any media 
    *		 
    */
    function f_check_session_attribute(in SDP_Message p_sdp, in template SDP_attribute p_attribute) runs on SipComponent return boolean {
		
        if (ispresent(p_sdp.attributes)) {
            for (var integer j:=0; j<sizeof(p_sdp.attributes); j:=j+1){			
                if (match(p_sdp.attributes[j],p_attribute)) {return(true);};
                };
        }
    	
        return(false);
    }
	
	 * 
	 * @desc 	identify an SDP direction attribute (session or first media attribute) in a SDP message and return its answer value
	 * @param 	p_sdp 		the SDP message that has been received
	 * @param 	p_attribute incoming SDP attribute that need to be used for the SDP direction (answer)
	 * @return 	the new attribute (to be send out) derived from the incoming SDP value
	 * @verdict 
	 */
	function f_get_attribute_answer(in SDP_Message p_sdp, in template SDP_attribute p_attribute) runs on SipComponent return SDP_attribute {

		var template SDP_attribute v_attribute := p_attribute;
		// check if the selected attribute is included in the SDP offer (session attributes)
		if (ispresent(p_sdp.attributes)) {
			for (var integer j:=0; j<sizeof(p_sdp.attributes); j:=j+1){			
				if (match(p_sdp.attributes[j],p_attribute)) {v_attribute := p_sdp.attributes[j];};
				};
		}

		// check if the selected attribute is included in the SDP offer (any of the media attributes)
		else {if (ispresent(p_sdp.media_list)) {
			for (var integer j:=0; j<sizeof(p_sdp.media_list); j:=j+1){			
				if (ispresent(p_sdp.media_list[j].attributes)) {
					for (var integer i:=0; i<sizeof(p_sdp.media_list[j].attributes); i:=i+1){			
						if (match(p_sdp.media_list[j].attributes[i],p_attribute)) 
							{v_attribute := p_sdp.media_list[j].attributes[i];};
						};
				}
				};
		select (valueof(v_attribute))
		{
			case (mw_attribute_sendonly) {return(valueof(m_attribute_recvonly));}