/* * Copyright (C) 2012 Doubango Telecom <http://www.doubango.org> * License: BSD * This file is part of Open Source sipML5 solution <http://www.sipml5.org> */ var TSIP_HEADER_MAX_FORWARDS_DEFAULT = 70; // Parse headers: 'Content-Length', 'Expires', 'Max-Forwards', 'Min-Expires', 'Min-SE', 'RSeq' tsip_header_Int.prototype = Object.create(tsip_header.prototype); tsip_header_Content_Length.prototype = Object.create(tsip_header_Int.prototype); tsip_header_Expires.prototype = Object.create(tsip_header_Int.prototype); tsip_header_Max_Forwards.prototype = Object.create(tsip_header_Int.prototype); tsip_header_Min_Expires.prototype = Object.create(tsip_header_Int.prototype); tsip_header_Min_SE.prototype = Object.create(tsip_header_Int.prototype); tsip_header_RSeq.prototype = Object.create(tsip_header_Int.prototype); %%{ machine tsip_machine_parser_header_Int; # Includes include tsip_machine_utils "./tsip_machine_utils.jrl"; action tag{ i_tag_start = p; } action parse_value{ if(o_hdr){ o_hdr.i_value = tsk_ragel_parser_get_int(s_str, p, i_tag_start); } } action parse_param{ if(o_hdr){ tsk_ragel_add_param(s_str, p, i_tag_start, o_hdr.ao_params); } } action is_Content_Length { o_hdr = new tsip_header_Content_Length(); } action is_Expires { o_hdr = new tsip_header_Expires(); } action is_Max_Forwards { o_hdr = new tsip_header_Max_Forwards(); } action is_Min_Expires { o_hdr = new tsip_header_Min_Expires(); } action is_Min_SE { o_hdr = new tsip_header_Min_SE(); } action is_RSeq { o_hdr = new tsip_header_RSeq(); } Int = ( ( "Content-Length"i | "l"i )%is_Content_Length | ("Expires"i)%is_Expires | ("Max-Forwards"i)%is_Max_Forwards | ("Min-Expires"i)%is_Min_Expires | ("Min-SE"i)%is_Min_SE | ("RSeq"i)%is_RSeq ) HCOLON (DIGIT+)>tag %parse_value ( (SEMI | COMMA) generic_param>tag %parse_param )*; action eob{ } # Entry point main := Int :>CRLF @eob; }%% %%write data; function tsip_header_Int(e_type, i_value){ tsip_header.call(this, e_type); this.i_value = i_value; } tsip_header_Int.prototype.toString = function(){ return typeof this.i_value == "undefined" ? null : this.i_value.toString(); }; tsip_header_Int.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 o_hdr = null; %%write init; %%write exec; if( cs < %%{ write first_final; }%% ){ tsk_utils_log_error("Failed to parse header: " + s_str); return null; } return o_hdr; } function tsip_header_Content_Length(i_value){ tsip_header_Int.call(this, tsip_header_type_e.Content_Length, i_value); } function tsip_header_Expires(i_value){ tsip_header_Int.call(this, tsip_header_type_e.Expires, i_value); } function tsip_header_Max_Forwards(i_value){ tsip_header_Int.call(this, tsip_header_type_e.Max_Forwards, i_value); } function tsip_header_Min_Expires(i_value){ tsip_header_Int.call(this, tsip_header_type_e.Min_Expires, i_value); } function tsip_header_Min_SE(i_value){ tsip_header_Int.call(this, tsip_header_type_e.Min_SE, i_value); } function tsip_header_RSeq(i_value){ tsip_header_Int.call(this, tsip_header_type_e.RSeq, i_value); }