I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP. The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines. Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON? Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)"); $var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" }}", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
A common solution to these problems is to base64-encode SIP data, so as to avoid any part of SIP grammar violating JSON encoding specs or conflicting with a JSON delimiter.
However, I'm not sure if whatever Janus is will accept that.
On Sun, Apr 21, 2019 at 06:15:22PM +0000, David Dean wrote:
I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP. The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines. Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON? Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)"); $var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" }}", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Agreed. Unfortunately Janus doesn't accept base64 at this time. I'll ask Lorenzo whether he can add base64 support, but in the interim I need to find a way in Kamailio of parsing $avp(sdp) as shell escaped plain text with the control characters replaced. Thanks.
On Sunday, 21 April 2019, 19:21:13 BST, Alex Balashov abalashov@evaristesys.com wrote:
A common solution to these problems is to base64-encode SIP data, so as to avoid any part of SIP grammar violating JSON encoding specs or conflicting with a JSON delimiter.
However, I'm not sure if whatever Janus is will accept that.
On Sun, Apr 21, 2019 at 06:15:22PM +0000, David Dean wrote:
I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP. The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines. Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON? Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)"); $var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" }}", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
I tried using s.replace to replace the control characters, but I don't think it recognises them:
$avp(sdp) = $(avp(sdp){s.replace,#015#012,\r\n});
It's the "#015#012" which is coming from sdp_get("$avp(sdp)"); that is the problem. On Sunday, 21 April 2019, 20:40:34 BST, David Dean just_bytesize@yahoo.co.uk wrote:
Agreed. Unfortunately Janus doesn't accept base64 at this time. I'll ask Lorenzo whether he can add base64 support, but in the interim I need to find a way in Kamailio of parsing $avp(sdp) as shell escaped plain text with the control characters replaced. Thanks.
On Sunday, 21 April 2019, 19:21:13 BST, Alex Balashov abalashov@evaristesys.com wrote:
A common solution to these problems is to base64-encode SIP data, so as to avoid any part of SIP grammar violating JSON encoding specs or conflicting with a JSON delimiter.
However, I'm not sure if whatever Janus is will accept that.
On Sun, Apr 21, 2019 at 06:15:22PM +0000, David Dean wrote:
I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP. The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines. Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON? Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)"); $var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" }}", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Your best bet is probably to run this through an embedded Python script or similar which exposes a chr() type function.
— Sent from mobile, with due apologies for brevity and errors.
On Apr 21, 2019, at 4:14 PM, David Dean just_bytesize@yahoo.co.uk wrote:
I tried using s.replace to replace the control characters, but I don't think it recognises them:
$avp(sdp) = $(avp(sdp){s.replace,#015#012,\r\n});
It's the "#015#012" which is coming from sdp_get("$avp(sdp)"); that is the problem.
On Sunday, 21 April 2019, 20:40:34 BST, David Dean just_bytesize@yahoo.co.uk wrote:
Agreed. Unfortunately Janus doesn't accept base64 at this time.
I'll ask Lorenzo whether he can add base64 support, but in the interim I need to find a way in Kamailio of parsing $avp(sdp) as shell escaped plain text with the control characters replaced.
Thanks.
On Sunday, 21 April 2019, 19:21:13 BST, Alex Balashov abalashov@evaristesys.com wrote:
A common solution to these problems is to base64-encode SIP data, so as to avoid any part of SIP grammar violating JSON encoding specs or conflicting with a JSON delimiter.
However, I'm not sure if whatever Janus is will accept that.
On Sun, Apr 21, 2019 at 06:15:22PM +0000, David Dean wrote:
I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP. The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines. Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON? Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)"); $var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" }}", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- Alex Balashov | Principal | Evariste Systems LLC
Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free) Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Digging into this a bit deeper, I now understand the exact problem. The issue is the difference in newlines between sdp_get output and the JSON format. sdp_get returns the SDP with unix newline characters i.e. \r\n.
However JSON won't accept unix newlines and requires a single line output with literal \r\n instead (i.e. escaped). So now I'm having to write the SDP into an external file using exec_msg, manipulate it with awk -v RS='\r?\n' -v ORS='\r\n' '1' and then bring it back into Kamailio. Not nice and also not yet working correctly yet. If there was a function within the JANSSON module to take a multi-line input (like the SDP) and convert it into a single line with literal \r\n characters ready for posting in a JSON message then that would make life much easier.
On Sunday, 21 April 2019, 19:15:22 BST, David Dean just_bytesize@yahoo.co.uk wrote:
I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP. The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines. Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON? Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)"); $var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" }}", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
Hello,
you can create a feature request if you like about this functionality.
Cheers,
Henning
Am 23.04.19 um 01:01 schrieb David Dean: Digging into this a bit deeper, I now understand the exact problem.
The issue is the difference in newlines between sdp_get output and the JSON format.
sdp_get returns the SDP with unix newline characters i.e. \r\n.
However JSON won't accept unix newlines and requires a single line output with literal \r\n instead (i.e. escaped).
So now I'm having to write the SDP into an external file using exec_msg, manipulate it with awk -v RS='\r?\n' -v ORS='\r\n' '1' and then bring it back into Kamailio. Not nice and also not yet working correctly yet.
If there was a function within the JANSSON module to take a multi-line input (like the SDP) and convert it into a single line with literal \r\n characters ready for posting in a JSON message then that would make life much easier.
On Sunday, 21 April 2019, 19:15:22 BST, David Dean just_bytesize@yahoo.co.ukmailto:just_bytesize@yahoo.co.uk wrote:
I'm trying to send an SDP from a SIP client to Janus using JSON over HTTP.
The problem is that Janus is erroring on the SDP content with the following error:
JANUS HTTP: Get SDP for echo plugin: {#012 "janus": "error",#012 "error": {#012 "code": 454,#012 "reason": "JSON error: on line 9: control character 0xd near '"v=0'"#012 }#012} Result code 200
I tried using {s.escape.common} to escape any quotations, commas etc but it doesn't appear to replace the control characters with newlines.
Any suggestions on how best to remove these control characters so that Janus will accept the SDP over JSON?
Here is the relevant section of kamailio.cfg:
# HTTP: Request SDP for echo test plugin sdp_get("$avp(sdp)");
$var(res) = http_connect("janus", "/janus/$var(JANUS-ID)/$var(ECHO-ID)", "application/json", "{ "janus" : "message", "transaction" : "testtesttest99", "body" : { "audio" : true }, "jsep" : { "type" : "offer", "sdp" : "$(avp(sdp){s.escape.common})" } }", "$avp(janus-pluginsession)"); xlog("L_INFO", "JANUS HTTP: Get SDP for echo plugin: $avp(janus-pluginsession) Result code $var(res)\n");
_______________________________________________ Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.orgmailto:sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- Henning Westerholt - https://skalatan.de/blog/ Kamailio services - https://skalatan.de/services