[asterisk-dev] Quoting in AGI data

Mark Michelson mmichelson at digium.com
Sun Feb 1 14:38:29 CST 2009


Alistair Cunningham wrote:
> Can someone from Digium please definitively say whether AGI data which 
> contains spaces should be quoted or not? I.e. which of the following 
> methods are correct?
>
> A. SET VARIABLE CALLERID(name) Test User
>
> B. SET VARIABLE CALLERID(name) "Test User"
>
> We've found that some Asterisk machines seem to produce the following 
> incorrect header on an outdoing SIP Dial() after using method A:
>
> From: "Test" <sip:101 at 1.2.3.4>;tag=as6cf271a2
>
> but do not do it for method B, while other machines do it for method B 
> but not A. We have been unable to determine why there's a difference in 
> behaviour.
>   

I took a look at Asterisk 1.4's res_agi.c and it appears that AGI 
commands are parsed with whitespace as a delimiter, unless that 
whitespace is in quotes. A command such as 'SET VARIABLE CALLERID(name) 
Test User' would have the following assignments in the argv array passed 
to the command handler:

argv[0] = SET
argv[1] = VARIABLE
argv[2] = CALLERID(name)
argv[3] = Test
argv[4] = User

The command handler for setting a variable only passes argv[3] to the 
pbx for setting the variable name, so I would expect that on current 1.4 
checkouts, using this command would incorrectly set the callerid name to 
be "Test" with "User" being completely ignored.

While I'll admit it's not the most thorough of investigations, I did a 
comparison of parse_args and handle_setvariable in res_agi.c between the 
1.4.0 tag, the 1.4 tip, the 1.2 tip, the 1.6.0 tip, and the current 
trunk, and found that they all are the same, so I'm at a bit of a loss 
here to try to explain where any particular change occurred. Can you 
specify what version of Asterisk you were using where the unquoted 
string actually worked?

tl;dr version:  the "correct" method from my code-reading is to use 
double quotes around the value used when using the SET VARIABLE command 
(the B method of your original message).

Mark Michelson



More information about the asterisk-dev mailing list