[Home]

Summary:ASTERISK-11236: [patch] agi SET VARIABLE does not allow the substitution of functions/variables.
Reporter:David Van Ginneken (davevg)Labels:
Date Opened:2008-01-14 15:01:59.000-0600Date Closed:2011-06-07 14:02:59
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Resources/res_agi
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) res_agi.diff
Description:res_agi does not properly substitute variables when using the SET VARIABLE command.  See additional information for agi debug trace before and after this patch.  Both 1.4 and trunk have this issue.

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

Before Patch:

AGI Rx << SET VARIABLE CHK_FILEEXIST "${STAT(e|/var/lib/asterisk/sounds/your.ulaw)}"
${STAT(e|/var/lib/asterisk/sounds/your.ulaw)}
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE CHK_FILEEXIST
AGI Tx >> 200 result=1 (${STAT(e|/var/lib/asterisk/sounds/your.ulaw)})
AGI Rx << SET VARIABLE CHK_FILENOTEXIST "${STAT(e|/var/lib/asterisk/sounds/this-file-does-not-exist.ulaw)}"
${STAT(e|/var/lib/asterisk/sounds/this-file-does-not-exist.ulaw)}
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE CHK_FILENOTEXIST
AGI Tx >> 200 result=1 (${STAT(e|/var/lib/asterisk/sounds/this-file-does-not-exist.ulaw)})
AGI Rx << SET VARIABLE DE "SOME-Long/Variable.with some characters"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE DE
AGI Tx >> 200 result=1 (SOME-Long/Variable.with some characters)
AGI Rx << SET VARIABLE RNDMTEXT "SOME-Long/Variable.with some characters"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE RNDMTEXT
AGI Tx >> 200 result=1 (SOME-Long/Variable.with some characters)
AGI Rx << SET VARIABLE CHKLEN "${LEN(resultisthelengthofthis)}"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE CHKLEN
AGI Tx >> 200 result=1 (${LEN(resultisthelengthofthis)})
AGI Rx << SET VARIABLE BE "HELLO"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE BE
AGI Tx >> 200 result=1 (HELLO)

After Patch:

AGI Rx << SET VARIABLE CHK_FILEEXIST "${STAT(e|/var/lib/asterisk/sounds/your.ulaw)}"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE CHK_FILEEXIST
AGI Tx >> 200 result=1 (1)
AGI Rx << SET VARIABLE CHK_FILENOTEXIST "${STAT(e|/var/lib/asterisk/sounds/this-file-does-not-exist.ulaw)}"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE CHK_FILENOTEXIST
AGI Tx >> 200 result=1 (0)
AGI Rx << SET VARIABLE DE "SOME-Long/Variable.with some characters"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE DE
AGI Tx >> 200 result=1 (SOME-Long/Variable.with some characters)
AGI Rx << SET VARIABLE RNDMTEXT "SOME-Long/Variable.with some characters"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE RNDMTEXT
AGI Tx >> 200 result=1 (SOME-Long/Variable.with some characters)
AGI Rx << SET VARIABLE CHKLEN "${LEN(resultisthelengthofthis)}"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE CHKLEN
AGI Tx >> 200 result=1 (23)
AGI Rx << SET VARIABLE BE "HELLO"
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE BE
AGI Tx >> 200 result=1 (HELLO)
Comments:By: Tilghman Lesher (tilghman) 2008-01-14 17:07:27.000-0600

Um, why aren't you doing the substitution directly in your AGI script?  It sounds like you're create a Rube Goldberg dialplan, by using the most inefficient use of AGI resources.  Just do the substitution directly in your AGI, and set only the result.

By: David Van Ginneken (davevg) 2008-01-14 19:22:39.000-0600

Not sure I understand.  My issue was I needed to be able to check for a specific file existence on the asterisk server using a FastAGI script which is not running on that server.  The other tests with other functions and strings were just to verify that those work as well.

By: Tilghman Lesher (tilghman) 2008-01-14 20:54:31.000-0600

So, in that case, you should do:

GET VARIABLE STAT(e|/var/lib/asterisk/sounds/your.ulaw)

There is no need to set the variable first, and retrieve the result.  Just get the value that you want.

By: David Van Ginneken (davevg) 2008-01-15 07:28:59.000-0600

Many thanks, I never thought of that.  I was constantly trying different ways of using SET VARIABLE and EXEC SET (I even went as far as trying TRYSYSTEM and SYSTEM using a shell script with a exit code) which were not working the ways I were trying.  *-users irc chat didn't respond with an answer/solution so I looked at the code.  I saw it was just not implemented in the SET VARIABLE command so I added it.  Never dawned on me to try using the GET directly.  Now I don't need this patch, but it still may be something worth going into /trunk for cases when this would be desirable.  Thanks again!

By: Tilghman Lesher (tilghman) 2008-01-15 08:57:45.000-0600

I really don't think there's a reason for that, as doing manipulations directly in AGI is far easier.