[Asterisk-Users] AGI GET Variable Problem
Kenige Ho
kengiepanda at gmail.com
Tue Dec 13 00:49:00 MST 2005
Dear All,
I am trying to get a variable via AGI "GET VARIABLE XXXX", but using AGI
DEBUG I actually do see the variable get return but somehow my retrieving
the variable via php. I don't get the value of the variable. Below is my
code and my results. Please help. thank you.
Coding:
#!/usr/bin/php -q
<?php
ob_implicit_flush(true);
set_time_limit(6);
$in = fopen("php://stdin","r");
$stdlog = fopen("/var/log/asterisk/my_agi.log", "w");
// toggle debugging output (more verbose)
$debug = false;
// Do function definitions before we start the main loop
function read() {
global $in, $debug;
$input = str_replace("\n", "", fgets($in, 4096));
if ($debug) fputs($stdlog, "read: $input\n");
return $input;
}
function errlog($line) {
global $err;
echo "VERBOSE \"$line\"\n";
}
function write($line) {
global $debug;
if ($debug) fputs($stdlog, "write: $line\n");
echo $line."\n";
}
// parse agi headers into array
while ($env=read()) {
$s = split(": ",$env);
// $agivar[str_replace("agi_","",$s[0])] = trim($s[1]);
// errlog($s[0].",".$s[1]);
$agivar[$s[0]] = trim($s[1]);
if(($endid.phpv=="") || ($env=="\n")) {
break;
}
}
// main program
echo "VERBOSE \"fone-check\"\n";
$tmp = "GET VARIABLE xxxxx";
write($tmp);
errlog("Temp Var is " . $tmp);
$result = read();
errlog("Before Strip Result is " . $result);
$result = trim(ereg_replace("200 result=1","",$result));
$result = trim(ereg_replace("\(","",$result));
$result = trim(ereg_replace("\)","",$result));
errlog("After Strip Result is " . $result);
// clean up file handlers etc.
fclose($in);
fclose($stdlog);
exit;
?>
Results:
AGI Debugging Enabled
AGI Tx >> agi_request: fone-check.agi
AGI Tx >> agi_channel: SIP/1234-adda
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1134460079.22
AGI Tx >> agi_callerid: 1234
AGI Tx >> agi_calleridname: 1234
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 1233
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: test
AGI Tx >> agi_extension: 1233
AGI Tx >> agi_priority: 11
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode: test
AGI Tx >>
AGI Rx << VERBOSE "fone-check"
fone-check.agi: fone-check
AGI Tx >> 200 result=1
AGI Rx << GET VARIABLE fone
AGI Tx >> 200 result=1 (555555)
AGI Rx << VERBOSE "Temp Var is GET VARIABLE fone"
fone-check.agi: Temp Var is GET VARIABLE fone
AGI Tx >> 200 result=1
AGI Rx << VERBOSE "Before Strip Result is 200 result=1"
fone-check.agi: Before Strip Result is 200 result=1
AGI Tx >> 200 result=1
AGI Rx << VERBOSE "After Strip Result is "
fone-check.agi: After Strip Result is
AGI Tx >> 200 result=1
Regards,
Kengie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20051213/b82f8cb2/attachment.htm
More information about the asterisk-users
mailing list