Trouble Applying Regex To Dialplan Variable That Contains Double-quotes
I am writing a dialplan context under asterisk 11.21.0 to handle SIP message routing between registered SIP peers using chan_sip. I am having trouble with double-quotes when the source peer uses a display name, which appears in quotes before the SIP URI. I
want to extract the SIP URI from MESSAGE(from) in order to (conditionally) route a failure message back to the source peer.
My test dialplan sets up variables like these:
exten => _X.,n,Set(RX=”.*<(.+)>“)
exten => _X.,n,Set(T1=”Example name”
If I just apply the regex operator (:) on T1 using regexp RX, like this:
exten => _X.,n,Set(FROM_SIPURI=$[${T1}:${RX}])
…I get this syntax error:
[2016-08-08 15:04:02] WARNING[1653][C-00000000]: ast_expr2.fl:470 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected ‘:’, expecting ‘-‘ or ‘!’ or ‘(‘ or ‘
“Example name”
^
(caret points at the colon character)
If I enclose the T1 variable in double quotes, like this:
exten => _X.,n,Set(FROM_SIPURI=$[“${T1}”:${RX}])
…I get this syntax error:
[2016-08-08 15:05:40] WARNING[1653][C-00000000]: ast_expr2.fl:470 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected ‘
“”Example name”
^
(caret points at letter E)
If I use the QUOTE() function to quote the double quotes before applying the regexp, like this:
exten => _X.,n,Set(FROM_SIPURI=$[${QUOTE(${T1})}:${RX}])
… I get this syntax error:
[2016-08-08 14:53:35] WARNING[1653][C-00000000]: ast_expr2.fl:470 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected ‘
“\”Example name\”
^
(caret points at letter E)
Currently I am working around the issue by using REPLACE() to strip all double-quotes, but I believe this is not a correct solution. How should I write the $[ expression so that the double-quotes are handled correctly?
2 thoughts on - Trouble Applying Regex To Dialplan Variable That Contains Double-quotes
How Set handles quotes can be changed with the ‘app_set’ setting in the
[compat] section of /etc/asterisk/asterisk.conf. See also:
https://wiki.asterisk.org/wiki/display/AST/Application_Set Perhaps you have the value left over from an old Asterisk setup.
El 08/08/16 a las 21:34, Eric Wieling escribi