tsdp_parser_header_O.jrl 2.33 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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/*
* 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_O.prototype = Object.create(tsdp_header.prototype);
%%{
	machine tsdp_machine_parser_header_O;

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

	action parse_username{
		hdr_O.s_username = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
	}

	action parse_sess_id{
		hdr_O.i_sess_id = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
	}

	action parse_sess_version{
		hdr_O.i_sess_version = tsk_ragel_parser_get_int(s_str, p, i_tag_start);
	}
	
	action parse_nettype{
		hdr_O.s_nettype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
	}

	action parse_addrtype{
		hdr_O.s_addrtype = tsk_ragel_parser_get_string(s_str, p, i_tag_start);
	}

	action parse_addr{
		hdr_O.s_addr= tsk_ragel_parser_get_string(s_str, p, i_tag_start);
	}

	username = js_any*>tag %parse_username;
	sess_id = DIGIT+>tag %parse_sess_id;
	sess_version = DIGIT+>tag %parse_sess_version;
	nettype = js_any*>tag %parse_nettype;
	addrtype = js_any*>tag %parse_addrtype;
	addr = js_any*>tag %parse_addr;
	O = 'o' SP* "=" SP*<: username :>SP sess_id :>SP sess_version :>SP nettype :>SP addrtype :>SP addr;
	
	# Entry point
	main := O :>CRLF?;

}%%


%%write data;

function tsdp_header_O(s_username, i_sess_id, i_sess_version, s_nettype, s_addrtype, s_addr){
	tsdp_header.call(this, tsdp_header_type_e.O);
	this.s_username = s_username;
	this.i_sess_id = i_sess_id;
	this.i_sess_version = i_sess_version;
	this.s_nettype = s_nettype;
	this.s_addrtype = s_addrtype;
	this.s_addr = s_addr;
}

tsdp_header_O.prototype.toString = function(){
	// o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com
	return tsk_string_format("{0} {1} {2} {3} {4} {5}",
		this.s_username,
		this.i_sess_id,
		this.i_sess_version,
		this.s_nettype,
		this.s_addrtype,
		this.s_addr);
}


tsdp_header_O.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_O = new tsdp_header_O(null, 0, 0, null, null, null);
	
	%%write init;
	%%write exec;
	
	if( cs < %%{ write first_final; }%% ){
		tsk_utils_log_error("Failed to parse \"o=\" header: " + s_str);
		return null;
	}
	
	return hdr_O;
}