From bc73ad81ed49e9d4d4f5a932da779843f009b327 Mon Sep 17 00:00:00 2001 From: predator314 Date: Wed, 7 Dec 2022 16:07:46 -0700 Subject: [PATCH] Fixed Asterisk 14+ event formatting issues Added limit to explode commands as any returned data containing additional : was being exploded to additional array elements and lost. ie. "Output: Something: Value" would only return "Something" Removed conditions that only non-blank lines are returned in data. This was making returned data differ from what AGI actually returns and didn't match Asterisk 13- results. Remove condition that data is only collected and returned if first Output: line is non-blank. This was causing any command issues that returned a blank line on line 1 to return no data. ie. "Action: Command Command: parking show default" would return no data since line 1 is always blank. --- src/phpagi-asmanager.php | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/phpagi-asmanager.php b/src/phpagi-asmanager.php index e2e7c2f..42d1431 100644 --- a/src/phpagi-asmanager.php +++ b/src/phpagi-asmanager.php @@ -188,11 +188,11 @@ function read_one_msg($allow_timeout = false) $parameters = array(); - $r = explode(': ', $msgarr[0]); + $r = explode(': ', $msgarr[0], 2); $type = strtolower($r[0]); if ($r[1] == 'Success' || $r[1] == 'Follows') { - $m = explode(': ', $msgarr[2]); + $m = explode(': ', $msgarr[2], 2); $msgarr_tmp = $msgarr; $str = array_pop($msgarr); $lastline = strpos($str, '--END COMMAND--'); @@ -200,17 +200,10 @@ function read_one_msg($allow_timeout = false) $parameters['data'] = substr($str, 0, $lastline-1); // cut '\n' too } else { if ($m[1] == 'Command output follows') { - $n = 3; - $c = count($msgarr_tmp) - 1; - $output = explode(': ', $msgarr_tmp[3]); - if ($output[1]) { - $data = $output[1]; - while ($n++<$c) { - $output = explode(': ', $msgarr_tmp[$n]); - if ($output[1]) { - $data .= "\n".$output[1]; - } - } + $data = ''; + for ($n=3; $n <= count($msgarr_tmp) - 1; $n++) { + $output = explode(': ', $msgarr_tmp[$n], 2); + $data .= ($n > 3?"\n":"") . $output[1]; $parameters['data'] = $data; } }