Commit fbee4f04 authored by juvancic's avatar juvancic
Browse files

Improved/updated calculation of message body lengths

parent da2be980
Loading
Loading
Loading
Loading
+412 −47
Original line number Diff line number Diff line
@@ -22,6 +22,12 @@ module LibSip_Templates
	import from LibSip_PIXITS all;
	import from LibSip_XMLTypes all;
	
	group ModuleParameters {
	
	    modulepar boolean MB_LENGTH_FROM_ENCVAL:=true; //* to get length of message body from ecoded value
	    modulepar boolean USE_FX_FOR_XML_LENGTH:=true; //* To use external functions for calculation of XML message/body length
	    
	}//* group ModuleParameters
	
	group SubFields
	{
@@ -2643,7 +2649,65 @@ group MessageBodies {
 */
group TemplatePreparationFunctions {

  group SDPlen_calculation {	
  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 {	
	/**
	 * 
	 * @desc Calculation of SDP length
@@ -2800,51 +2864,6 @@ group TemplatePreparationFunctions {
	  return v_result;
	};//* end function f_SDPlength

	/**
		 * 
		 * @desc Calculation of messagebody-textplain type length
		 * @param p_mb contain textplain message
		 * @return lenght
		 */
	function f_TextPlainLength(MessageBody p_mb) return integer
	{
	  var integer v_result:=2;
	  v_result:=v_result+lengthof(p_mb.textplain);
	  
	  return v_result;
	};//* end function f_SDPlength
		
	/**
	 * 
	 * @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;

		//*  assume SDP_Message ONLY in the message body
		if (ischosen(p_mb_par.sdpMessageBody))
		{ 
			v_result := f_SDPlength(p_mb_par.sdpMessageBody);
		};
// TODO f_XMLlength and f_MIMElength
 /*       //  assume XML_Message ONLY in the message body
        if (ischosen(p_mb_par.xmlBody))
        { 
        	v_result := f_XMLlength(p_mb_par.xmlBody);
        };

		//  assume MIME_Message in the message body
		if (ischosen(p_mb_par.mimeMessageBody))
		{ 
			v_result := f_MIMElength(p_mb_par.mimeMessageBody);
		};
*/
	return v_result
	};

	function f_SDPlength_connection(SDP_connection p_element) return integer //*  "c="
	{
	  var integer v_result:=0;
@@ -2900,7 +2919,353 @@ group TemplatePreparationFunctions {
		
  } //*  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))
				{ 
					v_result := f_XMLBody_CDIV_Length(p_mb.cdivn);
				};
				
				//  assume ICB ONLY in the XML message body
				if (ischosen(p_mb.icb))
				{ 
					v_result := f_XMLBody_ICB_Length(p_mb.icb);
				};
				
				//  assume OCB ONLY in the XML message body
				if (ischosen(p_mb.ocb))
				{ 
					v_result := f_XMLBody_OCB_Length(p_mb.ocb);
				};
				
				//  assume ResourceLists ONLY in the XML message body
				if (ischosen(p_mb.resourceLists))
				{ 
					v_result := f_XMLBody_ResourceList_Length(p_mb.resourceLists);
				};
				
				//  assume Ims3GPP ONLY in the XML message body
				if (ischosen(p_mb.ims3gpp))
				{ 
					v_result := f_XMLBody_Ims3GPP_Length(p_mb.ims3gpp);
				};
				
				/** Add aditional checks regarding to new variants,
				 *  also implement appropriate function for calculation
				 */
			}
			return v_result
		} //* f_XMLBodyLength
		
		group XMLBodies_calculation{
		
			/**
			* 
			* @desc Calculation of XML ConferenceInfo element length
			* @param p_mb contain XML ConfInfo body
			* @return xml_length
			*/
			function f_XMLBody_ConferenceInfo_Length(Conference_info p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_ConferenceInfo_Length
			
			/**
			* 
			* @desc Calculation of XML CUG element length
			* @param p_mb contain XML CUG body
			* @return xml_length
			*/
			function f_XMLBody_Cug_Length(Cug p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_Cug_Length
			
			/**
			* 
			* @desc Calculation of XML MCID element length
			* @param p_mb contain XML MCID body
			* @return xml_length
			*/
			function f_XMLBody_Mcid_Length(Mcid p_mb) return integer
			{
				var integer v_result:=0;
				
				if (ischosen(p_mb.choice.request)){
				
				}
				
				if (ischosen(p_mb.choice.response)){
				
				}
				
				return v_result
			} //* f_XMLBody_Mcid_Length
			
			/**
			* 
			* @desc Calculation of XML PSTNTransit element length
			* @param p_mb contain XML PSTNTransit body
			* @return xml_length
			*/
			function f_XMLBody_PSTNTransit_Length(PSTN_transit p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_PSTNTransit_Length
			
			/** @desc Calculation of XML Simservs element length
			* @param p_mb contain XML Simservs body
			* @return xml_length
			*/
			function f_XMLBody_Simservs_Length(Simservs p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_Simservs_Length	
			
			/** @desc Calculation of XML CDIV element length
			* @param p_mb contain XML CDIV body
			* @return xml_length
			*/
			function f_XMLBody_CDIV_Length(Comm_div_info p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_CDIV_Length		
			
			/** @desc Calculation of XML ICB length
			* @param p_mb contain XML ICB body
			* @return xml_length
			*/
			function f_XMLBody_ICB_Length(Incoming_communication_barring p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_ICB_Length
			
			/** @desc Calculation of XML OCB length
			* @param p_mb contain XML OCB body
			* @return xml_length
			*/
			function f_XMLBody_OCB_Length(Outgoing_communication_barring p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_OCB_Length
			
			/** @desc Calculation of XML ResourceList length
			* @param p_mb contain XML ResourceList body
			* @return xml_length
			*/
			function f_XMLBody_ResourceList_Length(Resource_lists p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_ResourceList_Length
			
			/** @desc Calculation of XML Ims3GPP length
			* @param p_mb contain XML Ims3GPP body
			* @return xml_length
			*/
			function f_XMLBody_Ims3GPP_Length(Ims_3gpp p_mb) return integer
			{
				var integer v_result:=0;
				//TODO: write function body
				return v_result
			} //* f_XMLBody_Ims3GPP_Length
			
		} //* XMLBodies_calculation
  	
  }//* group XMLlen_calculation

  group MIME_Len_calculation{
		/**
		* 
		* @desc Calculation of MIME length
		* @param p_mb contain MIME message
		* @return xml_length
		*/
		function f_MIMElength(MIME_Message p_mb) return integer
		{
			var integer v_result:=2; //0d0a
			
			v_result := v_result + lengthof(p_mb.boundary) + 2/*0d0a*/;
			
			for (var integer i:=0; i<sizeof(p_mb.mimeEncapsulatedList); i:=i+1){
				
				v_result := v_result + lengthof("Content-Type: ")+ lengthof(p_mb.mimeEncapsulatedList[i].content_type) + 2/*0d0a*/ ;
				
				if (ispresent(p_mb.mimeEncapsulatedList[i].content_disposition)){
					v_result := v_result + lengthof("Content-Disposition: ")+ lengthof(p_mb.mimeEncapsulatedList[i].content_disposition) + 2/*0d0a*/ ;
				}
				
				//v_result := v_result +2/*0d0a*/; ??? to check
				
				//		assume SDP_Message ONLY in the message body
        		if (ischosen(p_mb.mimeEncapsulatedList[i].mime_encapsulated_part.sdpMessageBody))
        		{ 
        			v_result := v_result + f_SDPlength(p_mb.mimeEncapsulatedList[i].mime_encapsulated_part.sdpMessageBody);
        		};
				
				//  assume XML_Body ONLY in the message body
            	if (ischosen(p_mb.mimeEncapsulatedList[i].mime_encapsulated_part.xmlBody))
            	{ 
            		v_result := v_result + f_XMLBody_Length(p_mb.mimeEncapsulatedList[i].mime_encapsulated_part.xmlBody, USE_FX_FOR_XML_LENGTH );
            	};
		
				//assume XML_Message ONLY in the message body
				if (ischosen(p_mb.mimeEncapsulatedList[i].mime_encapsulated_part.xmlMessage))
				{ 
					v_result := v_result + f_XMLlength(p_mb.mimeEncapsulatedList[i].mime_encapsulated_part.xmlMessage, USE_FX_FOR_XML_LENGTH );
				};
                
                //v_result := v_result +2/*0d0a*/; ??? to check
			}
			
			//v_result := v_result +2/*0d0a*/; ??? to check
			
			return v_result
		} //* f_MIMElength
  	
  }//* group MIMElen_calculation
  
  group TextPlain_Len_calculation{
		/**
		* 
		* @desc Calculation of messagebody-textplain type length
		* @param p_mb contain textplain message
		* @return lenght
		*/
		function f_TextPlainLength(MessageBody p_mb) return integer
		{
			var integer v_result:=2; //0d0a

			v_result:=v_result+lengthof(p_mb.textplain);
			
			return v_result;
		}//* end function f_TextPlainLength
		
  }//*end group TextPlainLen_calculation

  }//*group MessageBody_Calculation


  group GiveHeaders {