EvoluxBR / greenswitch

Battle proven FreeSWITCH Event Socket Protocol client implementation with Gevent
Other
126 stars 50 forks source link

Log events with a blank "User-Data" header malformed in ESLEvent #67

Open talmakion opened 3 years ago

talmakion commented 3 years ago

While ESLEvent works fine with normal events, it is possible to receive log events with no channel UUID, leaving the User-Data header blank. They look like:

Content-Length: 122
Log-Level: 4
Text-Channel: 0
Log-File: sofia_reg.c
Log-Func: sofia_reg_check_gateway
Log-Line: 510
User-Data: 

2021-04-03 19:05:48.882502 [WARNING] sofia_reg.c:510 ast-test-102 Failed Registration [503], setting retry to 30 seconds.

The User-Data line is 'User-Data: \n', including a space. Both the newline and space are stripped, and you end up with this (pretty-printed header dict) where User-Data is considered a continuation of the previous header:

{   'Content-Length': '122',
    'Content-Type': 'log/data',
    'Log-File': 'sofia_reg.c',
    'Log-Func': 'sofia_reg_check_gateway',
    'Log-Level': '4',
    'Log-Line': '510\nUser-Data:',
    'Text-Channel': '0'}

Removing the whitespace strip from ESLEvent.parse_data() doesn't seem to have any adverse affects on other events and fixes this issue:

{   'Content-Length': '122',
    'Content-Type': 'log/data',
    'Log-File': 'sofia_reg.c',
    'Log-Func': 'sofia_reg_check_gateway',
    'Log-Level': '4',
    'Log-Line': '510',
    'Text-Channel': '0',
    'User-Data': ''}
italorossi commented 2 years ago

*Need testing

talmakion commented 2 years ago

Is testing something I can assist with, or are you waiting for info from me?

italorossi commented 2 years ago

Yes, you can write a test case to make sure this event will be correctly parsed. refer to https://github.com/EvoluxBR/greenswitch/blob/8a457a7b10d2b28fc5bc8a9d245ae7ca4816b6a7/tests/test_lib_esl.py#L143

talmakion commented 2 years ago

Does this look better?