Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[asterisk-users] Trouble applying regex to dialplan variable that contains double-quotes


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> Asterisk Users
View previous topic :: View next topic  
Author Message
a_villacis at palosant...
Guest





PostPosted: Mon Aug 08, 2016 3:32 pm    Post subject: [asterisk-users] Trouble applying regex to dialplan variable Reply with quote

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" <sip:example@example.com>)

If I just apply the regex operator (Smile 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 '<token>'; Input:
"Example name" <sip:example@example.com>:".*<(.+)>"
^
(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 '<token>', expecting $end; Input:
""Example name" <sip:example@example.com>":".*<(.+)>"
^
(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 '<token>', expecting $end; Input:
"\"Example name\" <sip:example@example.com>":".*<(.+)>"
^
(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?


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
ewieling at nyigc.com
Guest





PostPosted: Mon Aug 08, 2016 9:43 pm    Post subject: [asterisk-users] Trouble applying regex to dialplan variable Reply with quote

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.

On 08/08/2016 04:31 PM, Alex Villací­s Lasso wrote:
Quote:
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" <sip:example@example.com>)

If I just apply the regex operator (Smile 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 '<token>'; Input:
"Example name" <sip:example@example.com>:".*<(.+)>"
^
(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
'<token>', expecting $end; Input:
""Example name" <sip:example@example.com>":".*<(.+)>"
^
(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
'<token>', expecting $end; Input:
"\"Example name\" <sip:example@example.com>":".*<(.+)>"
^
(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?



--
if at first you don't succeed, skydiving isn't for you


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
a_villacis at palosant...
Guest





PostPosted: Tue Aug 09, 2016 10:19 am    Post subject: [asterisk-users] Trouble applying regex to dialplan variable Reply with quote

El 08/08/16 a las 21:34, Eric Wieling escribió:
Quote:

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.


I do not have any [compat] section in my /etc/asterisk/asterisk.conf file. Also the previous assignments to RX and T1 work correctly and the values are set as they appear in the dialplan. It is only the evaluation of the regex operator inside the $[ that
gives me trouble. I thought the QUOTE() function would be the way to use a dialplan variable with special characters inside an expression, but apparently the backslash-double quote sequence is not being recognized as an escape sequence for a literal
double-quote character in the string. See below for the actual result. So, what am I doing wrong?

Quote:
On 08/08/2016 04:31 PM, Alex Villací­s Lasso wrote:
Quote:
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" <sip:example@example.com>)

If I just apply the regex operator (Smile 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 '<token>'; Input:
"Example name" <sip:example@example.com>:".*<(.+)>"
^
(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 '<token>', expecting $end; Input:
""Example name" <sip:example@example.com>":".*<(.+)>"
^
(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 '<token>', expecting $end; Input:
"\"Example name\" <sip:example@example.com>":".*<(.+)>"
^
(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?





--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> Asterisk Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services