/* * 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_T.prototype = Object.create(tsdp_header.prototype); %%{ machine tsdp_machine_parser_header_T; # Includes include tsdp_machine_utils "./tsdp_machine_utils.jrl"; action tag{ i_tag_start = p; } action parse_start_time{ hdr_T.i_start = tsk_ragel_parser_get_int(s_str, p, i_tag_start); } action parse_stop_time{ hdr_T.i_stop = tsk_ragel_parser_get_int(s_str, p, i_tag_start); } action parse_repeat_fields{ var o_hdr_R; if((o_hdr_R = tsdp_header_R.prototype.Parse(tsk_ragel_parser_get_string(s_str, p, i_tag_start)))){ this.ao_hdr_R.push(o_hdr_R); } } start_time = DIGIT+ >tag %parse_start_time; stop_time = DIGIT+ >tag %parse_stop_time; repeat_fields = any+ >tag %parse_repeat_fields; T = 't' SP* "=" SP*<: start_time :>SP stop_time (CRLF <:repeat_fields)?; # Entry point main := T :>CRLF?; }%% %%write data; function tsdp_header_T(i_start, i_stop){ tsdp_header.call(this, tsdp_header_type_e.T); this.i_start = i_start; this.i_stop = i_stop; this.ao_hdr_R = new Array(); } tsdp_header_T.prototype.toString = function(){ //"t=3034423619 3042462419\r\n" //"r=7d 1h 0 25h\r\n" // IMPORTANT: Do not append the last CRLF (because we only print the header value). var s_str = tsk_string_format( "{0} {1}", this.i_start, this.i_stop); for(var i = 0; i < this.ao_hdr_R.length; ++i){ if(i == 0){ s_str += "\r\n"; } s_str += tsk_string_format("{0}=", this.ao_hdr_R[i].e_type.s_name); s_str += this.ao_hdr_R[i]; if(i != (this.ao_hdr_R.length - 1)){ s_str += "\r\n"; } } return s_str; } tsdp_header_T.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_T = new tsdp_header_T(0, 0); %%write init; %%write exec; if( cs < %%{ write first_final; }%% ){ tsk_utils_log_error("Failed to parse \"t=\" header: " + s_str); return null; } return hdr_T; }