freeswitch / mod_mosquitto

mod_mosquitto is a FreeSWITCH interface to an MQTT broker using the Eclipse Mosquitto project C client library.
Other
3 stars 3 forks source link

Events are not a valid json messages #14

Closed antonwantstosleep closed 2 years ago

antonwantstosleep commented 3 years ago

Describe the bug

The mod is sending messages to the topic with an \x00 addition in the end:

2021-09-05 13:48:36 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on pbx/presence: b'{"Event-Name":"PRESENCE_PROBE","Core-UUID":"4be8dfd0-9f92-4262-b63f-4215d4919aba","FreeSWITCH-Hostname":"pbx.corp.loc","FreeSWITCH-Switchname":"pbx.corp.loc","FreeSWITCH-IPv4":"192.168.60.24","FreeSWITCH-IPv6":"::1","Event-Date-Local":"2021-09-05 13:48:36","Event-Date-GMT":"Sun, 05 Sep 2021 08:48:36 GMT","Event-Date-Timestamp":"1630831716485659","Event-Calling-File":"sofia_reg.c","Event-Calling-Function":"sofia_reg_handle_register_token","Event-Calling-Line-Number":"2130","Event-Sequence":"2644","proto":"sip","login":"internal","from":"1031@mc-vd.corp.loc","to":"1031@mc-vd.corp.loc","event_type":"presence","presence-source":"register","alt_event_type":"dialog"}\x00'

So JSON-parser can not parse it.

Maybe there is a need to trim / sanitize?

Sorry I can`t help with PR - I do not write in C++.

NormB commented 3 years ago

I can't test a fix right now, but something you can try is the following:

in mosquitto_events.c line 154

rc = mosquitto_publish(connection->mosq, &topic->mid, topic->pattern, strlen(buf)

try removing '+1' and see if that helps.

Norm

On Sun, Sep 5, 2021 at 5:10 AM antonwantstosleep @.***> wrote:

Describe the bug

The mod is sending messages to the topic with an \x00 addition in the end:

2021-09-05 13:48:36 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on pbx/presence: b'{"Event-Name":"PRESENCE_PROBE","Core-UUID":"4be8dfd0-9f92-4262-b63f-4215d4919aba","FreeSWITCH-Hostname":"pbx.corp.loc","FreeSWITCH-Switchname":"pbx.corp.loc","FreeSWITCH-IPv4":"192.168.60.24","FreeSWITCH-IPv6":"::1","Event-Date-Local":"2021-09-05 13:48:36","Event-Date-GMT":"Sun, 05 Sep 2021 08:48:36 @.**@.","event_type":"presence","presence-source":"register","alt_event_type":"dialog"}\x00'

So JSON-parser can not parse it.

Maybe there is a need to trim / sanitize?

Sorry I can`t help with PR - I do not write in C++.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/freeswitch/mod_mosquitto/issues/14, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQSIWOHSFPJLB4M26EEQSTUAMXYXANCNFSM5DOTLVPQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

NormB commented 2 years ago

Thank you for the report. Fix has been commited.