[Home]

Summary:ASTERISK-01801: extensions.conf breaks when there are commas inside of command arguments
Reporter:constfilin (constfilin)Labels:
Date Opened:2004-06-11 21:34:11Date Closed:2008-01-15 14:58:11.000-0600
Priority:TrivialRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) asterisk_commas.patch
Description:Asterisk seems to expand variables before they are passed as arguments to asterisk commands.
This creates a problem when - for example - there is an instruction

exten => s,1,App(${arg})

Assume that "arg" contains a comma within itself and equal to "1,2". After the variable
expansion, the insturction becomes

exten => s,1,App(1,2)

This passes to the application 2 arguments "1" and "2" instead of one argument "1,2".

The attached fix resolves this probelm by allowing to escape commas in the arguments.
After the patch if "arg" equals to "1\,2" then App gets a single argument "1,2".


****** ADDITIONAL INFORMATION ******

The fix is very useful when you have SQL queries in extensions.conf. E.G.: SELECT a,b,c FROM myTable;
Comments:By: Mark Spencer (markster) 2004-06-12 09:16:08

the "," to "|" conversion is done in pbx_config, while variable substitution for arguments is done at runtime since variables can change there.  Can you provide an example that demonstrates the behavior you're suggesting?  Consider the following example on an unpatched Asterisk:

[globals]
foo => 1,2

[default]
exten => 1902,1,Noop(${foo})
exten => 1902,2,Hangup

produces the following output:  

-- Executing NoOp("SIP/cisco1-6b99", "1,2") in new stack                  
-- Executing Hangup("SIP/cisco1-6b99", "") in new stack

Clearly, the substitution isn't taking place from "," to "|" in this case.

Obviously you can't use SetVar to put the comma outside of [globals] section, but you can declare a variable, say "C", whose value is a literal comma and use it.

By: Mark Spencer (markster) 2004-06-12 09:19:06

Oh, and do you have a disclaimer on file with us yet?  If not, we need you to send one in in order to apply your patch.  Thanks!

By: constfilin (constfilin) 2004-06-14 01:00:10

Mark, here is an example when Asterisk chokes on passing the arguments to an
application:

exten => s,18,PGSQL(Query otherQuery ${connID} SELECT callerid\,dispatch_action_1\,dispatch_action_2 FROM asterisk_blockednumbers WHERE extension_id=${extension_id})

Without slashes in front of commas application PGSQL gets 3 arguments instead of
one long argument for SQL query.

Yes, I did fax you the disclaimer to you last week. Let me know if you want me to re-fax it - cf@intermedia.net

Actually, I'm slashes are not the best solution. A beter solution is to use quotes -

exten => s,18,PGSQL("Query otherQuery ${connID} SELECT callerid,dispatch_action_1,dispatch_action_2 FROM asterisk_blockednumbers WHERE extension_id=${extension_id}")

My patch is supposed to support the quotes but I haven't actually tested it. I did test slashes, though. They work.

Thank you

Constantine

By: constfilin (constfilin) 2004-06-14 15:34:09

I tested how the patch works with quotes strings in command arguments - it works all right.

By: Mark Spencer (markster) 2004-06-14 16:39:20

Okay added to CVS.

By: Digium Subversion (svnbot) 2008-01-15 14:58:11.000-0600

Repository: asterisk
Revision: 3209

U   trunk/pbx/pbx_config.c

------------------------------------------------------------------------
r3209 | markster | 2008-01-15 14:58:10 -0600 (Tue, 15 Jan 2008) | 2 lines

Allow escaping of commas as well as ability to use quotes (bug ASTERISK-1801)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=3209