lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb in adhearsion-0.8.6 vs lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb in adhearsion-1.0.0

- old
+ new

@@ -1,28 +1,50 @@ + # line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" require File.join(File.dirname(__FILE__), 'ami_messages.rb') module Adhearsion module VoIP module Asterisk module Manager class AbstractAsteriskManagerInterfaceStreamLexer - BUFFER_SIZE = 8.kilobytes unless defined? BUFFER_SIZE + BUFFER_SIZE = 128.kilobytes unless defined? BUFFER_SIZE - # line 52 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" + ## + # IMPORTANT! See method documentation for adjust_pointers! + # + # @see adjust_pointers + # + POINTERS = [ + :@current_pointer, + :@token_start, + :@token_end, + :@version_start, + :@event_name_start, + :@current_key_position, + :@current_value_position, + :@last_seen_value_end, + :@error_reason_start, + :@follows_text_start, + :@current_syntax_error_start, + :@immediate_response_start + ] + + +# line 72 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" ## attr_accessor(:ami_version) def initialize @data = "" @current_pointer = 0 @ragel_stack = [] -# line 24 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" +# line 46 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" class << self attr_accessor :_ami_protocol_parser_actions private :_ami_protocol_parser_actions, :_ami_protocol_parser_actions= end self._ami_protocol_parser_actions = [ @@ -835,21 +857,22 @@ attr_accessor :ami_protocol_parser_en_response_follows end self.ami_protocol_parser_en_response_follows = 268; -# line 841 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" +# line 863 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" begin @current_pointer ||= 0 @data_ending_pointer ||= @data.length @current_state = ami_protocol_parser_start @ragel_stack_top = 0 @token_start = nil @token_end = nil @ragel_act = 0 end -# line 79 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" + +# line 98 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" ## end def <<(new_data) @@ -857,11 +880,11 @@ resume! end def resume! -# line 863 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" +# line 886 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" begin _klen, _trans, _keys, _acts, _nacts = nil _goto_level = 0 _resume = 10 _eof_trans = 15 @@ -887,16 +910,15 @@ while _nacts > 0 _nacts -= 1 _acts += 1 case _ami_protocol_parser_actions[_acts - 1] when 30 then -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 1 "NONE" begin @token_start = @current_pointer end -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" -# line 898 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" +# line 920 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" end # from state action switch end if _trigger_goto next end @@ -960,211 +982,180 @@ while _nacts > 0 _nacts -= 1 _acts += 1 case _ami_protocol_parser_actions[_acts - 1] when 0 then -# line 17 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 37 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin init_success end -# line 17 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 1 then -# line 19 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 39 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin init_response_follows end -# line 19 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 2 then -# line 21 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 41 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin init_error end -# line 21 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 3 then -# line 23 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 43 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin message_received @current_message end -# line 23 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 4 then -# line 24 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 44 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin error_received @current_message end -# line 24 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 5 then -# line 26 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 46 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin version_starts end -# line 26 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 6 then -# line 27 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin version_stops end -# line 27 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 7 then -# line 29 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 49 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin key_starts end -# line 29 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 8 then -# line 30 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 50 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin key_stops end -# line 30 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 9 then -# line 32 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 52 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin value_starts end -# line 32 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 10 then -# line 33 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 53 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin value_stops end -# line 33 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 11 then -# line 35 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 55 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin error_reason_starts end -# line 35 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 12 then -# line 36 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin error_reason_stops end -# line 36 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 13 then -# line 38 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 58 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin syntax_error_starts end -# line 38 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 14 then -# line 39 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 59 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin syntax_error_stops end -# line 39 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 15 then -# line 41 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 61 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin immediate_response_starts end -# line 41 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 16 then -# line 42 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 62 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin immediate_response_stops end -# line 42 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 17 then -# line 44 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 64 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin follows_text_starts end -# line 44 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 18 then -# line 45 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 65 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin follows_text_stops end -# line 45 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 19 then -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 67 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin event_name_starts end -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 20 then -# line 48 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 68 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" begin event_name_stops end -# line 48 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 21 then -# line 34 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 34 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_state = 152 _trigger_goto = true _goto_level = _again break end end -# line 34 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 22 then -# line 35 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 35 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_state = 152 _trigger_goto = true _goto_level = _again break end end -# line 35 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 23 then -# line 36 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 36 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_state = 152 _trigger_goto = true _goto_level = _again break end end -# line 36 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 24 then -# line 38 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 38 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_state = 268 _trigger_goto = true _goto_level = _again break end end -# line 38 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 25 then -# line 43 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 43 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @ragel_stack_top -= 1 @current_state = @ragel_stack[ @ragel_stack_top] _trigger_goto = true _goto_level = _again break end end -# line 43 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 26 then -# line 78 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 78 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_state = 262 _trigger_goto = true _goto_level = _again break end end -# line 78 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 27 then -# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin message_received @current_message; begin @current_state = 262 _trigger_goto = true _goto_level = _again break end end -# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 31 then -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 1 "NONE" begin @token_end = @current_pointer+1 end -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 32 then -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @ragel_act = 1; end -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 33 then -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 34 then -# line 48 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 48 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 begin begin @ragel_stack_top -= 1 @current_state = @ragel_stack[ @ragel_stack_top] @@ -1172,19 +1163,17 @@ _goto_level = _again break end end end -# line 48 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 35 then -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer @current_pointer = @current_pointer - 1; end -# line 47 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 36 then -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 1 "NONE" begin case @ragel_act when 0 then begin begin @current_state = 0 @@ -1196,26 +1185,24 @@ else begin begin @current_pointer = (( @token_end))-1; end end end end -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 37 then -# line 55 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 55 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 begin begin @current_state = 262 _trigger_goto = true _goto_level = _again break end end end -# line 55 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 38 then -# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 begin # If this scanner's look-ahead capability didn't match the prompt, let's ignore the need for a prompt @current_pointer = @current_pointer - 1; @@ -1226,13 +1213,12 @@ break end end end -# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 39 then -# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer @current_pointer = @current_pointer - 1; begin # If this scanner's look-ahead capability didn't match the prompt, let's ignore the need for a prompt @current_pointer = @current_pointer - 1; @@ -1243,13 +1229,12 @@ break end end end -# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 40 then -# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_pointer = (( @token_end))-1; end begin # If this scanner's look-ahead capability didn't match the prompt, let's ignore the need for a prompt @current_pointer = @current_pointer - 1; @@ -1260,62 +1245,54 @@ break end end end -# line 56 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 41 then -# line 64 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 64 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 64 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 42 then -# line 65 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 65 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 65 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 43 then -# line 66 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 66 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 66 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 44 then -# line 67 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 67 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 67 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 45 then -# line 68 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 68 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 68 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 46 then -# line 69 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 69 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 69 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 47 then -# line 70 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 70 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 begin begin @current_state = 262 _trigger_goto = true _goto_level = _again break end end end -# line 70 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 48 then -# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 begin # If NONE of the above patterns match, we consider this a syntax error. The irregularity machine can recover gracefully. @current_pointer = @current_pointer - 1; @@ -1328,13 +1305,12 @@ break end end end -# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 49 then -# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer @current_pointer = @current_pointer - 1; begin # If NONE of the above patterns match, we consider this a syntax error. The irregularity machine can recover gracefully. @current_pointer = @current_pointer - 1; @@ -1347,13 +1323,12 @@ break end end end -# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 50 then -# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_pointer = (( @token_end))-1; end begin # If NONE of the above patterns match, we consider this a syntax error. The irregularity machine can recover gracefully. @current_pointer = @current_pointer - 1; @@ -1366,47 +1341,40 @@ break end end end -# line 71 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 51 then -# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @ragel_act = 13; end -# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 52 then -# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @ragel_act = 15; end -# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 53 then -# line 83 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 83 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer+1 end -# line 83 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 54 then -# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer @current_pointer = @current_pointer - 1; end -# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 55 then -# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin @token_end = @current_pointer @current_pointer = @current_pointer - 1; end -# line 84 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 56 then -# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl" begin begin @current_pointer = (( @token_end))-1; end end -# line 82 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 57 then -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 1 "NONE" begin case @ragel_act when 0 then begin begin @current_state = 0 @@ -1418,12 +1386,11 @@ else begin begin @current_pointer = (( @token_end))-1; end end end end -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" -# line 1425 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" +# line 1392 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" end # action switch end end if _trigger_goto next @@ -1436,21 +1403,19 @@ while _nacts > 0 _nacts -= 1 _acts += 1 case _ami_protocol_parser_actions[_acts - 1] when 28 then -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 1 "NONE" begin @token_start = nil; end -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" when 29 then -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" +# line 1 "NONE" begin @ragel_act = 0 end -# line 1 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" -# line 1452 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" +# line 1417 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb" end # to state action switch end if _trigger_goto next end @@ -1476,27 +1441,62 @@ if _goto_level <= _out break end end end -# line 89 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" + +# line 108 "lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb" ## end def extend_buffer_with(new_data) - if new_data.size + @data.size > BUFFER_SIZE - @data.slice! 0...new_data.size - # TODO: What if the current_pointer wasn't at the end of the data for some reason? - @current_pointer = @data.size + length = new_data.size + + if length > BUFFER_SIZE + raise Exception, "ERROR: Buffer overrun! Input size (#{new_data.size}) larger than buffer (#{BUFFER_SIZE})" end + + if length + @data.size > BUFFER_SIZE + if @data.size != @current_pointer + if @current_pointer < length + # We are about to shift more bytes off the array than we have + # parsed. This will cause the parser to lose state so + # integrity cannot be guaranteed. + raise Exception, "ERROR: Buffer overrun! AMI parser cannot guarantee sanity. New data size: #{new_data.size}; Current pointer at #{@current_pointer}; Data size: #{@data.size}" + end + end + @data.slice! 0...length + adjust_pointers -length + end @data << new_data @data_ending_pointer = @data.size end protected ## + # This method will adjust all pointers into the buffer according + # to the supplied offset. This is necessary any time the buffer + # changes, for example when the sliding window is incremented forward + # after new data is received. + # + # It is VERY IMPORTANT that when any additional pointers are defined + # that they are added to this method. Unpredictable results may + # otherwise occur! + # + # @see https://adhearsion.lighthouseapp.com/projects/5871-adhearsion/tickets/72-ami-lexer-buffer-offset#ticket-72-26 + # + # @param offset Adjust pointers by offset. May be negative. + # + def adjust_pointers(offset) + POINTERS.each do |ptr| + value = instance_variable_get(ptr) + instance_variable_set(ptr, value + offset) if !value.nil? + end + end + + ## # Called after a response or event has been successfully parsed. # # @param [ManagerInterfaceResponse, ManagerInterfaceEvent] message The message just received # def message_received(message) @@ -1531,19 +1531,19 @@ def init_response_follows @current_message = ManagerInterfaceResponse.new end def init_error - @current_message = ManagerInterfaceError.new + @current_message = ManagerInterfaceError.new() end def version_starts - @start_of_version = @current_pointer + @version_start = @current_pointer end def version_stops - self.ami_version = @data[@start_of_version...@current_pointer].to_f - @start_of_version = nil + self.ami_version = @data[@version_start...@current_pointer].to_f + @version_start = nil end def event_name_starts @event_name_start = @current_pointer end