[asterisk-dev] Quoting in AGI data

Philipp Kempgen philipp.kempgen at amooma.de
Sun Feb 1 09:30:47 CST 2009


Alistair Cunningham schrieb:
> 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.

The behavior was changed in 1.4.something I think.

Here's a snippet of PHP code that works for me:

function gs_agi_str_esc( $str )
{
	$str = str_replace(
		array( '\\'  , ' '  , "\n" , "\r" , "\t" , '"'   ),
		array( '\\\\', '\\ ', '\\ ', '\\ ', '\\ ', '\\"' ),
		$str );
	return ($str == '' ? '""' : $str);
}

function gs_agi_set_variable( $name, $val )
{
	if (! preg_match('/^[a-zA-Z0-9_]+$/', $name)) return false;
	echo 'SET VARIABLE '. $name .' '. gs_agi_str_esc($val) ."\n";
	return true;
}

- It doesn't use quotes (except for an empty string).
- It escapes spaces with a backslash.
That seems to be most compatible with different versions of
Asterisk.

As I don't have a specification: sorry for sending a -users type
reply to -dev.


   Philipp Kempgen

-- 
AMOOCON 2009, May 4-5, Rostock / Germany   ->  http://www.amoocon.de
Asterisk: http://the-asterisk-book.com - http://das-asterisk-buch.de
AMOOMA GmbH - Bachstr. 126 - 56566 Neuwied  ->  http://www.amooma.de
Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998
-- 



More information about the asterisk-dev mailing list