tsdp_parser_header_V.jrl 1.12 KB
Newer Older
nextime's avatar
nextime committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/*
* Copyright (C) 2012 Doubango Telecom <http://www.doubango.org>
* License: BSD
* This file is part of Open Source sipML5 solution <http://www.sipml5.org>
*/

tsdp_header_V.prototype = Object.create(tsdp_header.prototype);
%%{
	machine tsdp_machine_parser_header_V;

	# Includes
	include tsdp_machine_utils "./tsdp_machine_utils.jrl";
	
	action tag{
		i_tag_start = p;
	}

	action parse_version{
		hdr_V.i_version = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
	}
		
	V = 'v' SP* "=" SP*<: DIGIT+>tag %parse_version;
	
	# Entry point
	main := V :>CRLF?;

}%%

%%write data;

function tsdp_header_V(i_version){
	tsdp_header.call(this, tsdp_header_type_e.V);
	this.i_version = i_version;
	this.toString = function(){
		return this.i_version.toString();
	}
}

tsdp_header_V.prototype.Parse = function(s_str){
	var cs = 0;
	var p = 0;
	var pe = s_str.length;
	var eof = pe;
	var data = tsk_buff_str2ib(s_str);
	var i_tag_start;	
	var hdr_V = new tsdp_header_V(0);
	
	%%write init;
	%%write exec;
	
	if( cs < %%{ write first_final; }%% ){
		tsk_utils_log_error("Failed to parse \"v=\" header: " + s_str);
		return null;
	}
	
	return hdr_V;
}