LibSip_Templates.ttcn 96.1 KB
Newer Older
rennoch's avatar
rennoch committed
	
	template Response mw_Response_PAsserted_Privacy_Supported (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template PAssertedID p_pAssertedID, template Privacy p_privacy, template Supported p_supported) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			pAssertedID := p_pAssertedID,
			privacy := p_privacy,
			supported := p_supported
		}
	}
			
	template Response m_Response_PAsserted_Privacy_mbody (StatusLine p_statusLine, CallId p_callId, CSeq p_cSeq,
			From p_from, To p_to, Via p_via, template PAssertedID p_pAssertedID, template Privacy p_privacy, MessageBody p_mb) modifies m_Response_ext:=
	{
		msgHeader :=
				{
						contentLength	:= {fieldName := CONTENT_LENGTH_E, len:= f_MessageBodyLength(valueof(p_mb))},
						contentType := {fieldName := CONTENT_TYPE_E, mediaType :=  c_sdpAplication},
						pAssertedID := p_pAssertedID,
						privacy := p_privacy
				},
				messageBody := p_mb
	}

} //*  end group response_send	


group response_receive {

	template Response mw_Response_Expires (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template DeltaSec p_deltaSec) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			expires := {fieldName := EXPIRES_E, deltaSec := p_deltaSec}
	  }
	}

	template Response mw_Response_PAsserted_Privacy (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template PAssertedID p_pAssertedID, template Privacy p_privacy) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			pAssertedID := p_pAssertedID,
			privacy := p_privacy
		}
	}

	template Response mw_Response_Reason (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, integer p_cause) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			reason := mw_Reason(p_cause)
			}
	}

	template Response mw_Response_RecordRoute (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template RecordRoute p_recordRoute) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			recordRoute := p_recordRoute
	  }
	}

	template Response mw_Response_Via (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template Via p_via) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			via := p_via
	  }
	}
	
	template Response mw_Response_Contact (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template Contact p_contact) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			contact := p_contact
	  }
	}
	
	template Response mw_Response_AlertInfo (
		template StatusLine p_statusLine, 
		template CallId p_callId,
		template CSeq p_cSeq, 
		template AlertInfo p_alertInfo
	) modifies mw_Response_Base:= {
		statusLine := {
			sipVersion := c_sipNameVersion, 
			statusCode := p_statusLine.statusCode, 
			reasonPhrase := ?
		},
		msgHeader :=
		{
			alertInfo := p_alertInfo
	  }
	}
	
rennoch's avatar
rennoch committed
	template Response mw_Response_HistoryInfo (template StatusLine p_statusLine, template CallId p_callId,
			template CSeq p_cSeq, template HistoryInfo p_historyInfo) modifies mw_Response_Base:=
		{
			statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
			msgHeader :=
			{
				historyInfo:=p_historyInfo
				}
		}
	
poglitsch's avatar
poglitsch committed
	template Response mw_Response_messageBody (
		template StatusLine p_statusLine, 
		template CallId p_callId,
		template CSeq p_cSeq, 
		template Require p_require,
		template MessageBody p_mb
	) modifies mw_Response_Base:= {
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			require := p_require
	    },
	    messageBody := p_mb
	}
	
	template Response mw_Response_Require (template StatusLine p_statusLine, template CallId p_callId,
		template CSeq p_cSeq, template Require p_require) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			require := p_require
	  }
	}
	
poglitsch's avatar
poglitsch committed
	template Response mw_Response_Require_ifpresent (template StatusLine p_statusLine, template CallId p_callId,
	template CSeq p_cSeq, template Require p_require) modifies mw_Response_Base:=
	{
		statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
		msgHeader :=
		{
			require := p_require ifpresent
	  }
	}
	
     template Response mw_Response_Supported (template StatusLine p_statusLine, template CallId p_callId,
      template CSeq p_cSeq, template Supported p_supported) modifies mw_Response_Base:=
     {
      statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
      msgHeader :=
      {
       supported := p_supported
       }
     }
rennoch's avatar
rennoch committed
     
     template Response mw_Response_UserToUser (template StatusLine p_statusLine, template CallId p_callId,
      template CSeq p_cSeq) modifies mw_Response_Base:=
     {
     statusLine := {sipVersion := c_sipNameVersion, statusCode := p_statusLine.statusCode, reasonPhrase := ?},
     msgHeader :=
     {
     	userToUser := ?
       }
     }
} //*  end group response_receive	
} //*  end group modified_templates	
} //*  end group MessageTemplates

group SDP_Templates {
	
	group SDP_Messages {

	group base_templates {
    	
    	template SDP_Message m_SDP(SDP_media_desc p_media, in SipUserProfile p_userprofile) := {
    		protocol_version := 0, //*  v=0
    		origin := {
    			user_name := "voicesession",
    			session_id := "30000",
    			session_version := "0",
    			net_type := c_in,
    			addr_type := c_ip4,
    			addr := p_userprofile.contactIpaddr },
    		//*  o=voicesession 12345 12345 IN IP4 172.27.1.219
    		session_name := "Voice Session", //*  s=Voice Session
    		information := omit,
    		uri := omit,
    		emails := omit,
    		phone_numbers := omit,
    		connection := {
    			net_type := c_in,
    			addr_type := c_ip4,
    			conn_addr := { addr:= p_userprofile.bearerIpaddr, ttl:=omit, num_of_addr:=omit }
    		}, //* c=IN IP4 172.27.1.219
    		bandwidth := omit,
    		times := { { time_field := { "0", "0" }, time_repeat:=omit
    			}
    		timezone_adjustments := omit,
    		key := omit,
    		attributes := omit,
    		media_list := {p_media}
    	};
    	
    	template SDP_Message m_SDP_mediaList(SDP_media_desc_list p_media_list, in SipUserProfile p_userprofile)
    	:= {
			protocol_version := 0, //*  v=0
			origin := {
				user_name := "voicesession",
				session_id := "30000",
				session_version := "0",
				net_type := c_in,
				addr_type := c_ip4,
				addr := p_userprofile.contactIpaddr },
			//*  o=voicesession 12345 12345 IN IP4 172.27.1.219
			session_name := "Voice Session", //*  s=Voice Session
			information := omit,
			uri := omit,
			emails := omit,
			phone_numbers := omit,
			connection := {
				net_type := c_in,
				addr_type := c_ip4,
				conn_addr := { addr:= p_userprofile.bearerIpaddr, ttl:=omit, num_of_addr:=omit }
			}, //* c=IN IP4 172.27.1.219
			bandwidth := omit,
			times := { { time_field := { "0", "0" }, time_repeat:=omit
				}
			timezone_adjustments := omit,
			key := omit,
			attributes := omit,
			media_list := p_media_list
		};

poglitsch's avatar
poglitsch committed
		template SDP_Message m_SDP_media_attr_preconditions(SDP_media_desc p_media, in SipUserProfile p_userprofile, SDP_attribute_list p_attribute_list)
		modifies m_SDP
		:= {
			media_list := {
				{
					media_field := {
						media := c_audio,
						ports := { port_number := 8500, num_of_ports:=omit },
						transport := c_rtpAvp,
						fmts := { "0" }
					}, //* m=audio 8500 RTP/AVP 0				
					information := omit,
					connections := omit,
					bandwidth := omit,
					key := omit,						
poglitsch's avatar
poglitsch committed
					attributes := p_attribute_list
				}}
			}
	
    		template SDP_Message m_SDP_attribute(SDP_media_desc p_media, in SipUserProfile p_userprofile, SDP_attribute loc_attribute) 
    		modifies m_SDP
    		:= {
    			attributes := {loc_attribute}
    		};

			template SDP_Message mw_SDP := {
				protocol_version := 0, //*  v=0
				origin := ?,
				session_name := ?, 
				information := omit,
				uri := omit,
				emails := omit,
				phone_numbers := omit,
				connection := ?,
				bandwidth := omit,
				times := { { time_field := { "0", "0" }, time_repeat:=omit
					}
				timezone_adjustments := omit,
				key := omit,
				attributes := omit,
				media_list := ?
			};
		
		
	}//* end group base_templates

	group modified_templates{
    	template SDP_Message m_SDP_bandwidth(SDP_media_desc p_media, in SipUserProfile p_userprofile) 
    	modifies m_SDP
    	:= {
    		bandwidth := {{PX_SIP_SDP_b_modifier, PX_SIP_SDP_b_bandwidth}}
    	};
    
    	template SDP_Message m_SDP_unacceptable(SDP_media_desc p_media, in SipUserProfile p_userprofile) 
    	modifies m_SDP
    	:= {
    		protocol_version := 1, //*  v=1 unacceptable version of SDP
    		bandwidth := {{PX_SIP_SDP_b_modifier, PX_SIP_SDP_b_bandwidth}}
    	};
    	
    	template SDP_Message m_SDP_encrypted(SDP_media_desc p_media, in SipUserProfile p_userprofile) 
    		modifies m_SDP
    		:= {
    			protocol_version := 1, //*  v=1 unacceptable version of SDP
    			bandwidth := {{PX_SIP_SDP_b_modifier, PX_SIP_SDP_b_bandwidth}}
    		};
    }//* end group modified_templates
	} //*  end group	SDP_Messages	
		
	group SDP_Fields {

		template SDP_media_desc m_media(template SDP_media_field p_mf) := {
				media_field := p_mf, 
				information := omit,
				connections := omit,
				bandwidth := omit,
				key := omit,						
				attributes := omit
		};
poglitsch's avatar
poglitsch committed
		template SDP_media_desc m_mediaFieldBandwdthAttributes(template SDP_media_field p_mf, template SDP_bandwidth p_bw, template SDP_attribute_list p_attributes) := {
				media_field := p_mf, 
				information := omit,
				connections := omit,
				bandwidth := p_bw,
				key := omit,						
				attributes := p_attributes
		};
		template SDP_media_desc m_media_dynPT(charstring p_PT, charstring p_encod) := {
				media_field := {
					media := c_audio,//* "audio",
					ports := { port_number := 8500, num_of_ports:=omit },
					transport := c_rtpAvp,//* "RTP/AVP",
				}, //* m=audio 8500 RTP/AVP 8
				information := omit,
				connections := omit,
				bandwidth := omit,
				key := omit,						
				attributes := { { rtpmap := { attr_value := p_PT & " " & p_encod }
								}
		};
	
		template SDP_media_desc m_media_unsupported := {
				media_field := {
					media := "video",
					ports := { port_number := 11500, num_of_ports:=omit },
					transport := "RTP/AVP",
					fmts := { "99" }
				}, //* m=audio 8500 RTP/AVP 0
				information := omit,
				connections := omit,
				bandwidth := omit,
				key := omit,						
				attributes := { { 
					rtpmap := { attr_value := "99 X-Experimental/180000"}
				}}
		};

		template SDP_bandwidth m_bandwidth(template charstring loc_m, template integer loc_b) := {
			modifier:=loc_m, 
			bandwidth:=loc_b
		};

		template SDP_bandwidth m_bandwidth_as_64:= 
		{
					modifier:="AS", 
					bandwidth:=64
		}
		
		template SDP_bandwidth mw_bandwidth_rs:= 
		{
					modifier:="RS", 
					bandwidth:=?
		}
		
		template SDP_bandwidth mw_bandwidth_rr:= 
		{
					modifier:="RR", 
					bandwidth:=?
		}

		template SDP_media_field m_media_field(charstring p_media, integer p_portNum, charstring p_transport, charstring p_fmts) :=
		{
			media := p_media,
			ports := { port_number := p_portNum, num_of_ports:=omit },
			transport := p_transport,
			fmts := { p_fmts }
		}		

        template SDP_media_field mw_media_PCMU :=
        {
			media := c_audio,
			ports := { port_number := ?, num_of_ports:=* },
			transport := c_rtpAvp,
			fmts := { "0" }
        }

		template SDP_media_field mw_media_PCMA :=
		{
			media := c_audio,
poglitsch's avatar
poglitsch committed
			ports := { port_number := 8500, num_of_ports:=omit },
			transport := c_rtpAvp,
			fmts := { "8" }
		}
		
		template SDP_media_field mw_media_PCMA_U_DPT :=
		{
			media := c_audio,
			ports := { port_number := ?, num_of_ports:=* },
			transport := c_rtpAvp,
			fmts := { * }
		}
		
		template SDP_media_field mw_media_T38 :=
		{
			media := c_image,
			ports := { port_number := ?, num_of_ports:=* },
			transport := pattern "*ptl", //* udptl,tcptl
			fmts := { "t38" }
		}

		template SDP_media_field mw_media_G722 :=
		{
			media := c_audio,
			ports := { port_number := ?, num_of_ports:=* },
			transport := "RTP/AVP",
			fmts := { "9" }
		}

		template SDP_media_field mw_media_AMR_DPT :=
		{
			media := c_audio,
			ports := { port_number := ?, num_of_ports:=* },
			transport := c_rtpAvp,
			fmts := { * }
		}
		

		template SDP_attribute m_attribute_sendonly	 := {sendonly:={}};
		template SDP_attribute mw_attribute_sendonly	 := {sendonly:={}};//MRO
		template SDP_attribute m_attribute_recvonly	 := {recvonly:={}};
		template SDP_attribute mw_attribute_recvonly	 := {recvonly:={}};//MRO
		template SDP_attribute m_attribute_sendrecv	 := {sendrecv:={}};
		template SDP_attribute mw_attribute_sendrecv	 := {sendrecv:={}};//MRO
		template SDP_attribute m_attribute_inactive	 := {inactive:={}};
		template SDP_attribute mw_attribute_inactive	 := {inactive:={}};//MRO
		template SDP_attribute mw_attribute_sendonly_inactive := (mw_attribute_sendonly,mw_attribute_inactive);
		template SDP_attribute mw_attribute_sendrecv_recvonly_omit := (mw_attribute_sendrecv,mw_attribute_recvonly,omit);
		template SDP_attribute m_attribute_AMR_DPT	 := { rtpmap := { attr_value := /*pattern "**/PX_SIP_SDP_dyn & " AMR" }};
		template SDP_attribute m_attribute_CLEARMODE_DPT	 := {rtpmap := { attr_value := /*pattern "**/PX_SIP_SDP_dyn & " CLEARMODE/8000" }};
		template SDP_attribute m_attribute_G722	 := { rtpmap := { attr_value := "9 G722/8000" }};
		template SDP_attribute m_attribute_PCMU	 := { rtpmap := { attr_value := "0 PCMU/8000" }};
		template SDP_attribute m_attribute_PCMU_DPT	 := { rtpmap := { attr_value := /*pattern "**/PX_SIP_SDP_dyn & " PCMU/8000" }};
		template SDP_attribute m_attribute_PCMA	 := { rtpmap := { attr_value := "8 PCMA/8000" }};
		template SDP_attribute m_attribute_PCMA_DPT	 := { rtpmap := { attr_value := /*pattern "**/PX_SIP_SDP_dyn & " PCMA/8000" }};
		template SDP_attribute m_attribute_T38	 := { unknown := { name:=?, attr_value := pattern "*t38*" }};
		
		template SDP_attribute m_attribute_curr (charstring p_preconditionType, charstring p_statusType, charstring p_direction):= 
		{
			curr:={preconditionType := p_preconditionType, 
			statusType := p_statusType, 
			direction := p_direction}
		};
poglitsch's avatar
poglitsch committed
		
		template SDP_attribute mw_attribute_curr := 
		{
			curr := ?
		};
		
		template SDP_attribute m_attribute_des (charstring p_preconditionType, charstring p_strength, charstring p_statusType, charstring p_direction):= 
		{
			des:={preconditionType := p_preconditionType, 
			strength := p_strength,
			statusType := p_statusType, 
			direction := p_direction}
		};
poglitsch's avatar
poglitsch committed
		
		template SDP_attribute mw_attribute_des := 
		{
			des := ?
		};
		
		template SDP_attribute m_attribute_conf (charstring p_preconditionType, charstring p_statusType, charstring p_direction):= 
		{
			conf:={preconditionType := p_preconditionType, 
			statusType := p_statusType, 
			direction := p_direction}
poglitsch's avatar
poglitsch committed
		};		
} //*  end group SDP_Templates

group MessageBodies {
	
	template MessageBody m_MBody_SDP(template SDP_Message p_SDP):=
	{
		sdpMessageBody := p_SDP
	};
	
	template MessageBody m_MBody_XML(template XmlBody p_xmlBody):=
	{
		xmlBody := p_xmlBody
	};
	
	template MessageBody m_MBody_longPlainText:=
	{
		textplain :=  c_longMessageContent_1300Bytes
	};

	template MessageBody m_mBody_plainText(charstring p_plaitext):=
	{
		textplain :=  p_plaitext
	};
	
	template MessageBody m_MBody_sipfrag(charstring p_sipfrag) := {
		sipfrag := p_sipfrag	
	} 
	
	template MessageBody m_MBody_MIMESdpXml(template SDP_Message p_sdp, template XmlBody p_xmlBody):=
	{
		mimeMessageBody := {boundary:="PX_SIP_MIME_Boundary", 
			mimeEncapsulatedList:= {
			{content_type:="PX_SIP_SDP_ContentType", 
				content_disposition:=omit,
				mime_encapsulated_part:={sdpMessageBody := p_sdp}},
			{content_type:="PX_SIP_ISUP_ContentType", 
				content_disposition:=omit,
				mime_encapsulated_part:={xmlBody := p_xmlBody}}
			}
		}
	}
	
	template MessageBody mw_MBody_SDP(template SDP_Message p_SDP):=
	{
		sdpMessageBody := p_SDP
	};
	
	template MessageBody mw_MBody_XML(template XmlBody p_xmlBody):=
	{
		xmlBody := p_xmlBody
	};
	
	template MessageBody mw_MBody_MIMESdpXml(template SDP_Message p_sdp, template XmlBody p_xmlBody):=
	{
		mimeMessageBody := {boundary:=?, 
			mimeEncapsulatedList:= {
			{content_type:=?, 
				content_disposition:=*,
				mime_encapsulated_part:={sdpMessageBody := p_sdp}},
			{content_type:=?, 
				content_disposition:=*,
				mime_encapsulated_part:={xmlBody := p_xmlBody}}
			}
		}
	}
	
	template MessageBody mw_MBody_MIME_Ims3gpp(
		template charstring p_disposition, 
		template Ims_3gpp p_ims3gpp
	):= {
		mimeMessageBody := {boundary:=?, 
			mimeEncapsulatedList:= {
    			*,
    			{	
    				content_type:= c_ims3gppAplication, 
    				content_disposition:= p_disposition,
    				mime_encapsulated_part :={
    					xmlBody := {
    						ims3gpp := 	p_ims3gpp
    					}
    				}
    			},
    			*
			}
		}
	}
	
	template MessageBody mw_MBody_MIME_Ims3gppCW(
		template charstring p_disposition, 
		template Ims_3gpp p_ims3gpp
	):= {
		mimeMessageBody := {boundary:=?, 
			mimeEncapsulatedList:= {
							*,
							{	
								content_type:= c_ims3gppCwApplication, 
								content_disposition:= p_disposition,
								mime_encapsulated_part :={
									xmlBody := {
										ims3gpp := 	p_ims3gpp
									}
								}
							},
							*
			}
		}
	}	
	
 * @desc group TemplatePreparationFunctions contain functions which are used for templates
 */
group TemplatePreparationFunctions {

  group MessageBody_Calculation{
  	
	/**
	* 
	* @desc Calculation of Message Body length
	* @param p_mb_par contain message body part
	* @return message body length
	*/
	function f_MessageBodyLength(MessageBody p_mb_par) return integer {

		var integer v_result:=0;
		if (MB_LENGTH_FROM_ENCVAL){ //by default it is set to true 
			
            v_result:= lengthof(encvalue(p_mb_par))/8; // length in bypes, let get length of encoded value
		}
		else{ 
        
            //  assume SDP_Message ONLY in the message body
    		if (ischosen(p_mb_par.sdpMessageBody))
    		{ 
    			v_result := f_SDPlength(p_mb_par.sdpMessageBody);
    		};
    
    	    //  assume XML_Body ONLY in the message body
    		if (ischosen(p_mb_par.xmlBody))
    		{ 
    			v_result := f_XMLBody_Length(p_mb_par.xmlBody, USE_FX_FOR_XML_LENGTH );
    		};
    		
            //assume XML_Message ONLY in the message body
            if (ischosen(p_mb_par.xmlMessage))
            { 
            	v_result := f_XMLlength(p_mb_par.xmlMessage, USE_FX_FOR_XML_LENGTH );
            };
    
    		//  assume MIME_Message in the message body
    		if (ischosen(p_mb_par.mimeMessageBody))
    		{ 
    			v_result := f_MIMElength(p_mb_par.mimeMessageBody);
    		};
    		
            //assume sipfrag in the message body
            if (ischosen(p_mb_par.sipfrag))
            { 
            	v_result := f_TextPlainLength(p_mb_par); //same function due to same type with textplain
            };
            
            //assume textplain in the message body
            if (ischosen(p_mb_par.textplain))
            { 
            	v_result := f_TextPlainLength(p_mb_par);
            };
		}

	  return v_result
	}
  	
  	
  group SDP_Len_calculation {	
reinaortega's avatar
reinaortega committed
	 * 
	 * @desc Calculation of SDP length
	 * @param p_mb contain sdp message
	 * @return sdp_lenght
	 */
	function f_SDPlength(SDP_Message p_mb) return integer
	{
	  var integer v_result:=2; //*  due to empty line beginning of message body
	  var charstring v_auxstring;
	  	
	  v_result := 2+c_CRlen + lengthof(int2str(p_mb.protocol_version)); //*  "v="
	  v_result := v_result + 2+c_CRlen + lengthof(p_mb.origin.user_name & " " & 
								  p_mb.origin.session_id & " " & 
								  p_mb.origin.session_version & " " & 
								  p_mb.origin.net_type & " " & 
								  p_mb.origin.addr_type & " " & 
								  p_mb.origin.addr           
								  ); //*  "o="
	  v_result := v_result + 2+c_CRlen + lengthof(p_mb.session_name); //*  "s="
	  if (ispresent(p_mb.information)) 
		{v_auxstring:=p_mb.information; v_result := v_result + 2+c_CRlen + lengthof(v_auxstring);}; //*  "i= "
	  if (ispresent(p_mb.uri)) 
		{v_auxstring:=p_mb.uri; v_result := v_result + 2+c_CRlen + lengthof(v_auxstring);}; //*  "u="
			
	  if (ispresent(p_mb.emails)) {
		for (var integer i:=0; i<sizeof(p_mb.emails); i:=i+1)
		{v_result := v_result + 2+c_CRlen + lengthof(p_mb.emails[i].addr_or_phone); //*  "e="
		if (ispresent(p_mb.emails[i].disp_name)) 
		  {v_auxstring:=p_mb.emails[i].disp_name; v_result := v_result + 1 + lengthof(v_auxstring);};
		};
	  };
			
	  if (ispresent(p_mb.phone_numbers)) {
		for (var integer i:=0; i<sizeof(p_mb.phone_numbers); i:=i+1)
		  {v_result := v_result + 2+c_CRlen + lengthof(p_mb.phone_numbers[i].addr_or_phone); //*  "p= "
		  if (ispresent(p_mb.phone_numbers[i].disp_name)) 
			{v_auxstring:=p_mb.phone_numbers[i].disp_name; v_result := v_result + 1 + lengthof(v_auxstring);};
		};
	  }; 
		    
	  if (ispresent(p_mb.connection)) 
	  {
		var integer v_len_con0 := f_SDPlength_connection(p_mb.connection);
		v_result := v_result + v_len_con0;
			
	  if (ispresent(p_mb.bandwidth))   
	  { 
		for (var integer i:=0; i<sizeof(p_mb.bandwidth); i:=i+1) { //*  "b= "
		  v_result := v_result + 2+c_CRlen + lengthof(p_mb.bandwidth[i].modifier & " ") + 
		  lengthof(int2str(p_mb.bandwidth[i].bandwidth));
		}						
	  };
	
reinaortega's avatar
reinaortega committed
	  for (var integer i:=0; i<sizeof(p_mb.times); i:=i+1) {
		v_result := v_result + 2+c_CRlen + lengthof(p_mb.times[i].time_field.start_time & " "
					 & p_mb.times[i].time_field.stop_time);//*  "t="
									  
		if (ispresent(p_mb.times[i].time_repeat))
		{
		  for (var integer j:=0; j<sizeof(p_mb.times[i].time_repeat); j:=j+1)
			v_result := v_result + 2+c_CRlen + lengthof(int2str(p_mb.times[i].time_repeat[j].repeat_interval.time)); //*  "r="
			if (ispresent(p_mb.times[i].time_repeat[j].repeat_interval.unit)) 
			{
			  v_auxstring:=p_mb.times[i].time_repeat[j].repeat_interval.unit; 
			  v_result := v_result + 1 + lengthof(v_auxstring);
			};					
					
			v_result := v_result + 1 + lengthof(int2str(p_mb.times[i].time_repeat[j].active.time));
			if (ispresent(p_mb.times[i].time_repeat[j].active.unit)) 
			{
			  v_auxstring:=p_mb.times[i].time_repeat[j].active.unit; 
			  v_result := v_result + 1 + lengthof(v_auxstring);
			};
										
			for (var integer k:=0; k<sizeof(p_mb.times[i].time_repeat[j].offsets); k:=k+1)
			{
			  v_result := v_result + 1 + lengthof(int2str(p_mb.times[i].time_repeat[j].offsets[k].time));
			  if (ispresent(p_mb.times[i].time_repeat[j].offsets[k].unit)) 
			  {
				v_auxstring:=p_mb.times[i].time_repeat[j].offsets[k].unit; 
				v_result := v_result + 1 + lengthof(v_auxstring);
			  };
			}		
		  }
		};
	  };

	  if (ispresent(p_mb.timezone_adjustments)) 
		{log("timezone adjustments have not been considered in SDP length calculation yet");
				
	  if (ispresent(p_mb.key)) {
		v_result := v_result + 2+c_CRlen + lengthof(p_mb.key.method); //*  "k= "
		if (ispresent(p_mb.key.key)) 
		   {v_auxstring:=p_mb.key.key; v_result := v_result + 1 + lengthof(v_auxstring);};
	  }; 
	  if (ispresent(p_mb.attributes)) {
		for (var integer i:=0; i<sizeof(p_mb.attributes); i:=i+1){ //*  "a= "
			var integer v_len_con1 := f_SDPlength_attribute(p_mb.attributes[i]);
			v_result := v_result + v_len_con1;
		};

	  if (ispresent(p_mb.media_list)) 
	  {  
        for (var integer i:=0; i<sizeof(p_mb.media_list); i:=i+1){ //*  "m= "
		  //*  for each media_field
		  //* log("p_mb.media_list[i] ",p_mb.media_list[i]);
		  v_result := v_result + 2+c_CRlen + lengthof(p_mb.media_list[i].media_field.media)
							 + 1 + lengthof(int2str(p_mb.media_list[i].media_field.ports.port_number));


		  if (ispresent(p_mb.media_list[i].media_field.ports.num_of_ports)) 
			{v_result := v_result + 1 + lengthof(int2str(p_mb.media_list[i].media_field.ports.num_of_ports));};
		  v_result := v_result + 1 + lengthof(p_mb.media_list[i].media_field.transport);
		  for (var integer j:=0; j<sizeof(p_mb.media_list[i].media_field.fmts); j:=j+1){	
			v_result := v_result + 1 + lengthof(valueof(p_mb.media_list[i].media_field.fmts[j]));
		  }
						
		  if (ispresent(p_mb.media_list[i].information)) {
			v_auxstring:=p_mb.media_list[i].information;
			v_result := v_result + 2+c_CRlen + lengthof(v_auxstring);  //*  "i= "
		  };
		  if (ispresent(p_mb.media_list[i].connections)) {
			for (var integer j:=0; j<sizeof(p_mb.media_list[i].media_field.fmts); j:=j+1){	
			  var integer v_len_con2 :=  f_SDPlength_connection(p_mb.media_list[i].connections[j]);
			  v_result := v_result + v_len_con2;
		  if (ispresent(p_mb.media_list[i].bandwidth)) {  //*  "b= "
		  	v_result := v_result + 2+c_CRlen + lengthof(p_mb.media_list[i].bandwidth.modifier)
						+ 1 + lengthof(int2str(p_mb.media_list[i].bandwidth.bandwidth));
		  };
		  if (ispresent(p_mb.media_list[i].key)) {   //*  "k= "
			v_result := v_result + 1 + lengthof(p_mb.media_list[i].key.method);
			if (ispresent(p_mb.media_list[i].key.key)) {
			  v_auxstring := p_mb.media_list[i].key.key;
			  v_result := v_result + 1 + lengthof(v_auxstring);
			};				
		  };
		  if (ispresent(p_mb.media_list[i].attributes)) {
			for (var integer j:=0; j<sizeof(p_mb.media_list[i].attributes); j:=j+1){ //*  "a= "
			  var integer v_len_attr := f_SDPlength_attribute(p_mb.media_list[i].attributes[j]);
			  v_result := v_result + v_len_attr;
		}; //*  end for i	  	
	  }; //*  end if media_list
	};//* end function f_SDPlength
	function f_SDPlength_connection(SDP_connection p_element) return integer //*  "c="
	{
	  var integer v_result:=0;
	  var charstring v_auxstring;
	  v_result := v_result + 2+c_CRlen + lengthof(p_element.net_type & " " & 
	  p_element.addr_type & " " & 
	  p_element.conn_addr.addr);
	   if (ispresent(p_element.conn_addr.ttl)) 
		  {v_result := v_result + 1 + lengthof(int2str(p_element.conn_addr.ttl));}; 
	   if (ispresent(p_element.conn_addr.num_of_addr)) 
		  {v_result := v_result + 1 + lengthof(int2str(p_element.conn_addr.num_of_addr));};
	   return v_result
	} //*  f_SDPlength_connection
	function f_SDPlength_attribute(SDP_attribute p_element) return integer //*  "a="
	{
	  var integer v_result:=0;
	  var charstring v_auxstring;
	  if (ischosen(p_element.cat)) {v_result := v_result + 2+c_CRlen + lengthof("cat:" & p_element.cat.attr_value)};
	  if (ischosen(p_element.keywds)) {v_result := v_result + 2+c_CRlen + lengthof("keywds:" & p_element.keywds.attr_value)};
	  if (ischosen(p_element.tool)) {v_result := v_result + 2+c_CRlen + lengthof("tool:" & p_element.tool.attr_value)};
	  if (ischosen(p_element.ptime)) {v_result := v_result + 2+c_CRlen + lengthof("ptime:" & p_element.ptime.attr_value)};
	  if (ischosen(p_element.recvonly)) {v_result := v_result + 2+c_CRlen + lengthof("recvonly")};
	  if (ischosen(p_element.sendrecv)) {v_result := v_result + 2+c_CRlen + lengthof("sendrecv")};
	  if (ischosen(p_element.sendonly)) {v_result := v_result + 2+c_CRlen + lengthof("sendonly")};
	  if (ischosen(p_element.inactive)) {v_result := v_result + 2+c_CRlen + lengthof("inactive")};
	  if (ischosen(p_element.orient)) {v_result := v_result + 2+c_CRlen + lengthof("orient:" & p_element.orient.attr_value)};
	  if (ischosen(p_element.sdp_type)) {v_result := v_result + 2+c_CRlen + lengthof("type:" & p_element.sdp_type.attr_value)};
	  if (ischosen(p_element.charset)) {v_result := v_result + 2+c_CRlen + lengthof("charset" & p_element.charset.attr_value)};
	  if (ischosen(p_element.sdplang)) {v_result := v_result + 2+c_CRlen + lengthof("sdplang:" & p_element.sdplang.attr_value)};
	  if (ischosen(p_element.lang)) {v_result := v_result + 2+c_CRlen + lengthof("lang:" & p_element.lang.attr_value)};
	  if (ischosen(p_element.framerate)) {v_result := v_result + 2+c_CRlen + lengthof("framerate:" & p_element.framerate.attr_value)};
	  if (ischosen(p_element.quality)) {v_result := v_result + 2+c_CRlen + lengthof("quality:" & p_element.quality.attr_value)};
	  if (ischosen(p_element.fmtp)) {v_result := v_result + 2+c_CRlen + lengthof("fmtp:" & p_element.fmtp.attr_value)};
	  if (ischosen(p_element.curr)) {v_result := v_result + 2+c_CRlen + lengthof("curr:" & p_element.curr.preconditionType & " " 
										& p_element.curr.statusType & " " & p_element.curr.direction)};
	  if (ischosen(p_element.des)) {v_result := v_result + 2+c_CRlen + lengthof("des:" & p_element.des.preconditionType & " " 
										& p_element.des.strength & " " & p_element.des.statusType & " " & p_element.des.direction)};
	  if (ischosen(p_element.conf)) {v_result := v_result + 2+c_CRlen + lengthof("conf:" & p_element.conf.preconditionType & " " 
										& p_element.des.statusType & " " & p_element.des.direction)};
	  if (ischosen(p_element.rtpmap)) {v_result := v_result + 2+c_CRlen + lengthof("rtpmap:" & p_element.rtpmap.attr_value)};
	  if (ischosen(p_element.rtcp)) {v_result := v_result + 2+c_CRlen + lengthof("rtcp:" & p_element.rtcp.attr_value)};
	  if (ischosen(p_element.unknown)) 
	  {v_result := v_result + 2+c_CRlen + lengthof(p_element.unknown.name);
		if (ispresent(p_element.unknown.attr_value))		   		
		  {var charstring aux := p_element.unknown.attr_value;
			v_result := v_result + lengthof(":" & p_element.unknown.attr_value);
		};
	  };
	  //*  log("axr: length attribute=", v_result);
	} //*  f_SDPlength_attribute
  } //*  group SDPlen_calculation	
  group XML_Len_calculation{
		
		/**
		* @desc Declaration of external functions to calculate length of message bodies
		* switching of internal or external functions are made by boolean module parameter/PIXIT
		* USE_FX_FOR_XML_LENGTH declared at top of this module
		*/
		external function fx_calculateXMLMessageLen(XMLMessage p_mb) return integer;
		external function fx_calculateXMLBodyLen(XmlBody p_mb) return integer;
		
		/**
		* 
		* @desc Calculation of XML length
		* @param p_mb contain XML message
		* @return xml_length
		*/
		function f_XMLlength(XMLMessage p_mb, boolean p_ext_func) return integer
		{
			var integer v_result:=0;
			
			if ( p_ext_func){
				v_result := fx_calculateXMLMessageLen(p_mb);
			}else{
				if (ispresent(p_mb.header)){
					v_result := f_XMLHeader_Length(p_mb.header);
				}
				
				//false given, because decision of external function usage is done in first if statement
				v_result := v_result + f_XMLBody_Length(p_mb.body, false); 
			}
			return v_result
		} //* f_XMLlength
		
		/**
		* 
		* @desc Calculation of XML header length
		* @param p_mh contain XML header 
		* @return xml_header_length
		*/
		function f_XMLHeader_Length(XmlHeader p_mh) return integer
		{
			var integer v_result:=0;
			
			//*<?xml version="1.0" encoding="UTF-8"?>\n len=39*/
			//* 2 3          1   1          1     1 2 1*/
			
			v_result:=2+3+lengthof(" version=")+1+lengthof(p_mh.version)+1;  //<?xml version="1.0"
			
			if (ispresent(p_mh.encoding)){
				
				v_result:=v_result+lengthof(" encoding=")+1+lengthof(p_mh.encoding)+1;  // encoding="UTF-8"
			}
			
			if (ispresent(p_mh.anyAttributes)){
				for (var integer i:=0; i<sizeof(p_mh.anyAttributes); i:=i+1){
					v_result := v_result + 1 + lengthof(p_mh.anyAttributes[i].name)+ 2 + lengthof(p_mh.anyAttributes[i].val) + 1;
					//vresult + " "(1)+ length(name) + "=\""(2) + length(val) + "\""(1)
				}
			}
			
			v_result:=v_result+2+1; //?>\n
			
			return v_result
		} //* f_XMLHeaderLength
		
		/**
		* 
		* @desc Calculation of XML body length
		* @param p_mb contain XML body
		* @return xml_length
		*/
		function f_XMLBody_Length(XmlBody p_mb, boolean p_ext_func) return integer
		{
			var integer v_result:=0;
			
			if ( p_ext_func){
				v_result := fx_calculateXMLBodyLen(p_mb);
			}else{
				//  assume ConferenceInfo ONLY in the XML message body
				if (ischosen(p_mb.conferenceInfo))
				{ 
					v_result := f_XMLBody_ConferenceInfo_Length(p_mb.conferenceInfo);
				};
				
				//  assume CUG ONLY in the XML message body
				if (ischosen(p_mb.cug))
				{ 
					v_result := f_XMLBody_Cug_Length(p_mb.cug);
				};
				
				//  assume MCID ONLY in the XML message body
				if (ischosen(p_mb.mcid))
				{ 
					v_result := f_XMLBody_Mcid_Length(p_mb.mcid);
				};
				
				//  assume PSTNTransit ONLY in the XML message body
				if (ischosen(p_mb.pstnTransit))
				{ 
					v_result := f_XMLBody_PSTNTransit_Length(p_mb.pstnTransit);
				};
				
				//  assume Simservs ONLY in the XML message body
				if (ischosen(p_mb.simservs))
				{ 
					v_result := f_XMLBody_Simservs_Length(p_mb.simservs);
				};
				
				//  assume CDIV ONLY in the XML message body
				if (ischosen(p_mb.cdivn))
				{