Phpagi GET FULL VARIABLE

When trying to run get_fullvariable(“MD5(string)”) in phpagi the only response I get is

 [code] => 520
 [result] => 
 [data] => Invalid command syntax.  Proper usage follows: Returns <literal>0</literal> if <replaceable>variablename</replaceable> is not set. Returns <literal>1</literal> if <replaceable>variablename</replaceable> is set and returns the variable in parentheses.

Any thoughts?

It is a syntax error on your PHP code, nothing related to Asterisk

http://phpagi.sourceforge.net/phpagi22/api-docs/phpAGI/AGI.html#get_fullvariable

wow thanks for pointing that out.

Now when I try to get the MD5 of a string I am getting [data] => MD5(khjgkfj

Thoughts?

for posterity https://sourceforge.net/p/phpagi/bugs/20/

I think you’re trying to write condensed PHP code. Which is resulting in syntax errors that are not related to asterisk. Stop trying to write condensed code -and- use conlog everywhere so you can identify coding issues.

<?php
$string = "some value";
$agi->conlog("set the string: $string");
$hash = MD5($string);
$agi->conlog("MD5 hash: $hash");
$full = $agi->get_fullvariable($hash);
$agi->conlog("got the full variable: $full");
?>

Once it is all working, then you can try to condense the code.

Not trying to condense the php. I am trying to run an asterisk function, in this case it is MD5 because it is a quick and easy example.

The example you provided, is basically function_a(function_b("string")), a.k.a. condensed.
My point, was break down each operation separately, especially for testing, and use conlog everywhere. At least until the code functions as expected.

I prefer verbose() to conlog.

GET FULL VARIABLE is supposed to be able to return the result of a an asterisk function. I am testing this ability using MD5(), an asterisk function.

“function_a” is a class function provided by phpAGI. That function takes in a string. In this case the string is “MD5(string)”. “functionb_b” is not a php function it is a string to be evaluated by asterisk.

Sources:
http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/AGI-communication.html#AGI_id242030
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+AGICommand_get+full+variable
https://wiki.asterisk.org/wiki/display/AST/Asterisk+16+Function_MD5
http://phpagi.sourceforge.net/phpagi22/api-docs/

Based on my personal expirience, Asterisk functions should be use on the dial plan directly and then pass the value of them to your AGI as parameter, trying to use function inside the phagi class could lead to an un expected result, I might be wrong but that is my thought

Asterisk functions don’t take the evaluation of of other functions as their arguments. What I suspect happens in the dialplan is that the PBX code evaluates functions from the inside to the outside, so that each actual function is only passed the literal values of its arguments. Certainly the code that actually implements a function will not parse its arguments for function calls.

Incidentally, I strongly suspect that both AGI and ARI are overused for things better done in dialplan.

verbose() -or- conlog(), they both achieve the same goal.


Since MD5() is also a PHP function, makes it harder to answer your question. When using asterisk functions within phpAGI functions, you need to pay close attention to parameter quoting.

...
 same => n,NoOp(MD5(test))
 same => n,NoOp(MD5('test'))
 same => n,NoOp(${MD5('test()})
 same => n,Hangup()

[Nov 18 08:33:48] -- Executing [s@realtime:3] NoOp("SIP/024c", "MD5(test)") in new stack
[Nov 18 08:33:48] -- Executing [s@realtime:4] NoOp("SIP/024c", "MD5('test')") in new stack
[Nov 18 08:33:48] -- Executing [s@realtime:5] NoOp("SIP/024c", "daf07005ebcbb590b87b080d06fc5392") in new stack

Then the use MD5() with $phpAGI->get_fullvariable() is likely chasing an unknown variable. Variables should be set and existing in the dialplan. I personally prefer PHP functions over asterisk functions in the AGI script. Since PHP would be the active interpreter.

[dialplan_context]
...
 same => n,Set(daf07005ebcbb590b87b080d06fc5392="my md5 vale")
 same => n,Set(${MD5("test_string")}="another md5 vale")
 same => n,AGI(path/to/file.php)

<?php
$phpAGI->get_fullvariable("daf07005ebcbb590b87b080d06fc5392");
$var = MD5("test_string");
$phpAGI->get_fullvariable($var);
?>
1 Like