/* * 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_R.prototype = Object.create(tsdp_header.prototype); %%{ machine tsdp_machine_parser_header_R; # Includes include tsdp_machine_utils "./tsdp_machine_utils.jrl"; action tag{ i_tag_start = p; } action parse_repeat_interval{ hdr_R.s_repeat_interval = tsk_ragel_parser_get_string(s_str, p, i_tag_start); } action parse_typed_time{ tsk_ragel_parser_add_string(s_str, p, i_tag_start, hdr_R.as_typed_times); } fixed_len_time_unit = "d" | "h" | "m" | "s"; repeat_interval = (DIGIT+ fixed_len_time_unit?) >tag %parse_repeat_interval; typed_time = (DIGIT+ fixed_len_time_unit?) >tag %parse_typed_time; R = 'r' SP* "=" SP*<: repeat_interval :>SP typed_time (SP<: typed_time)+; # Entry point main := R :>CRLF?; }%% %%write data; function tsdp_header_R(s_repeat_interval, s_typed_time){ tsdp_header.call(this, tsdp_header_type_e.R); this.s_repeat_interval = s_repeat_interval; this.as_typed_times = new Array(); if(s_typed_time){ this.as_typed_times.push(s_typed_time); } } tsdp_header_R.prototype.toString = function(){ // r=7d 1h 0 25h var s_str = this.s_repeat_interval; for(var i = 0; i < this.as_typed_times.length; ++i){ s_str += " " + this.as_typed_times[i]; } return s_str; } tsdp_header_R.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_R = new tsdp_header_R(null, null); %%write init; %%write exec; if( cs < %%{ write first_final; }%% ){ tsk_utils_log_error("Failed to parse \"r=\" header: " + s_str); return null; } return hdr_R; }