diff --git a/greenswitch/esl.py b/greenswitch/esl.py index c9cdd8d..f67d466 100644 --- a/greenswitch/esl.py +++ b/greenswitch/esl.py @@ -122,7 +122,10 @@ def handle_event(self, event): else: length = int(event.headers['Content-Length']) data = self._read_socket(self.sock_file, length) - event.parse_data(data) + if event.headers.get('Content-Type') == 'log/data': + event.data = data + else: + event.parse_data(data) self._esl_event_queue.put(event) def _safe_exec_handler(self, handler, event): @@ -148,6 +151,10 @@ def process_events(self): handlers = self.event_handlers.get(event.headers.get('Event-Subclass')) else: handlers = self.event_handlers.get(event.headers.get('Event-Name')) + + if not handlers and event.headers.get('Content-Type') == 'log/data': + handlers = self.event_handlers.get('log') + if not handlers: continue diff --git a/tests/__init__.py b/tests/__init__.py index 0a04916..b4eed26 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -32,6 +32,11 @@ def send_fake_event_plain(self, data): self.switch_esl.fake_event_plain(data.encode('utf-8')) gevent.sleep(0.1) + def send_fake_raw_event_plain(self, data): + self.switch_esl.fake_raw_event_plain(data.encode('utf-8')) + gevent.sleep(0.1) + + def send_batch_fake_event_plain(self, events): for event in events: self.send_fake_event_plain(event) diff --git a/tests/fakeeslserver.py b/tests/fakeeslserver.py index 9d10c48..48d5f9b 100644 --- a/tests/fakeeslserver.py +++ b/tests/fakeeslserver.py @@ -95,6 +95,9 @@ def fake_event_plain(self, data): 'Content-Length: %s' % len(data)]) self._client_socket.send(data) + def fake_raw_event_plain(self, data): + self._client_socket.send(data) + def disconnect(self): self.protocol_send(['Content-Type: text/disconnect-notice', 'Content-Length: 67']) diff --git a/tests/test_lib_esl.py b/tests/test_lib_esl.py index de8563e..4e0a9c7 100644 --- a/tests/test_lib_esl.py +++ b/tests/test_lib_esl.py @@ -128,6 +128,28 @@ def on_heartbeat(self, event): self.send_fake_event_plain(event_plain) self.assertTrue(self.esl.heartbeat) + def test_event_socket_data(self): + """Should call registered handler for events.""" + self.log = False + + def on_log(event): + self.log = True + self.esl.register_handle('log', on_log) + event_plain = dedent("""\ + Content-Type: log/data + Content-Length: 126 + Log-Level: 7 + Text-Channel: 3 + Log-File: switch_core_state_machine.c + Log-Func: switch_core_session_destroy_state + Log-Line: 710 + User-Data: 4c882cc4-cd02-11e6-8b82-395b501876f9 + + 2016-12-28 10:34:08.398763 [DEBUG] switch_core_state_machine.c:710 (sofia/internal/7071@devitor) State DESTROY going to sleep +""") + self.send_fake_raw_event_plain(event_plain) + self.assertTrue(self.log) + def test_event_with_multiline_channel_variables_content(self): """Should not break parse from ESL Event when.""" def on_channel_create(self, event):