Tidy up exception handling
Simplify handling of AMI lists and trap exceptions
This commit is contained in:
parent
a89866e81e
commit
5beee7f9a2
|
@ -184,19 +184,17 @@ class SCCPGeneric_Response extends Response
|
||||||
|
|
||||||
public function addEvent($event)
|
public function addEvent($event)
|
||||||
{
|
{
|
||||||
// not eventlist (start/complete)
|
if ($event->getEventList() === 'start') {
|
||||||
// print_r('<br>---- addEvent --<br>');
|
// Have started a list of events; this may include tables
|
||||||
// print_r($event);
|
// Nothing to do with this event, only need to handle
|
||||||
// print_r('<br>---- Event List--<br>');
|
// the events that follow
|
||||||
// print_r($event->getEventList());
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Nothing to do with this - we need a table start
|
|
||||||
if (stristr($event->getEventList(), 'start')) { return; }
|
|
||||||
|
|
||||||
// This is empty as soon as we have received a TableStart.
|
|
||||||
// The next message is the first of the data sets
|
|
||||||
// We use this variable in the switch to add set entries
|
|
||||||
if ( empty($thisSetEventEntryType)) {
|
if ( empty($thisSetEventEntryType)) {
|
||||||
|
// This is empty as soon as we have received a TableStart.
|
||||||
|
// The next message is the first of the data sets
|
||||||
|
// We use this variable in the switch to add set entries
|
||||||
if (strpos($event->getName(), 'Entry')) {
|
if (strpos($event->getName(), 'Entry')) {
|
||||||
$thisSetEventEntryType = $event->getName();
|
$thisSetEventEntryType = $event->getName();
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,44 +202,44 @@ class SCCPGeneric_Response extends Response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$unknownevent = "FreePBX\\modules\\Sccp_manager\\aminterface\\UnknownEvent";
|
$unknownevent = "FreePBX\\modules\\Sccp_manager\\aminterface\\UnknownEvent";
|
||||||
if (!($event instanceof $unknownevent)) {
|
if ($event instanceof $unknownevent) {
|
||||||
switch ( $event->getName()) {
|
$this->_events[] = $event;
|
||||||
case $thisSetEventEntryType :
|
return;
|
||||||
$this->_temptable['Entries'][] = $event;
|
}
|
||||||
break;
|
switch ( $event->getName()) {
|
||||||
case 'TableStart':
|
case $thisSetEventEntryType :
|
||||||
//initialise
|
$this->_temptable['Entries'][] = $event;
|
||||||
$this->_temptable = array();
|
break;
|
||||||
$this->_temptable['Name'] = $event->getTableName();
|
case 'TableStart':
|
||||||
$this->_temptable['Entries'] = array();
|
//initialise
|
||||||
$thisSetEventEntryType = '';
|
$this->_temptable = array();
|
||||||
break;
|
$this->_temptable['Name'] = $event->getTableName();
|
||||||
case 'TableEnd':
|
$this->_temptable['Entries'] = array();
|
||||||
//Close
|
$thisSetEventEntryType = '';
|
||||||
if (!is_array($this->_tables)) {
|
break;
|
||||||
$this->_tables = array();
|
case 'TableEnd':
|
||||||
}
|
//Close
|
||||||
$this->_tables[$event->getTableName()] = $this->_temptable;
|
if (!is_array($this->_tables)) {
|
||||||
unset($this->_temptable);
|
$this->_tables = array();
|
||||||
$thisSetEventEntryType = '';
|
|
||||||
|
|
||||||
// Finished the table. Now check to see if everything was received
|
|
||||||
// If counts do not match return false and table will not be
|
|
||||||
//loaded
|
|
||||||
if ($event->getKey('TableEntries') != count($this->_tables[$event->getTableName()]['Entries'])) {
|
|
||||||
return $this->_completed = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// add regular event
|
|
||||||
$this->_events[] = $event;
|
|
||||||
}
|
}
|
||||||
} else {
|
$this->_tables[$event->getTableName()] = $this->_temptable;
|
||||||
// add unknown event
|
$this->_temptable = array();
|
||||||
|
$thisSetEventEntryType = 'undefinedAsThisIsNotASet';
|
||||||
|
|
||||||
|
// Finished the table. Now check to see if everything was received
|
||||||
|
// If counts do not match return false and table will not be
|
||||||
|
//loaded
|
||||||
|
if ($event->getKey('TableEntries') != count($this->_tables[$event->getTableName()]['Entries'])) {
|
||||||
|
return $this->_completed = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// add regular list event
|
||||||
$this->_events[] = $event;
|
$this->_events[] = $event;
|
||||||
}
|
}
|
||||||
// Received a complete eventList outside of a table.
|
|
||||||
if (stristr($event->getEventList(), 'complete') || stristr($event->getName(), 'complete')) {
|
if ($event->getEventList() === 'Complete') {
|
||||||
|
// Received a complete eventList.
|
||||||
return $this->_completed = true;
|
return $this->_completed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,7 +250,6 @@ class SCCPGeneric_Response extends Response
|
||||||
$_rawtable = $this->Table2Array($_tablename);
|
$_rawtable = $this->Table2Array($_tablename);
|
||||||
// Check that there is actually data to be converted
|
// Check that there is actually data to be converted
|
||||||
if (empty($_rawtable)) { return $result;}
|
if (empty($_rawtable)) { return $result;}
|
||||||
|
|
||||||
foreach ($_rawtable as $_row) {
|
foreach ($_rawtable as $_row) {
|
||||||
$all_key_ok = true;
|
$all_key_ok = true;
|
||||||
// No need to test if $_fkey is arrray as array required
|
// No need to test if $_fkey is arrray as array required
|
||||||
|
@ -264,11 +261,12 @@ class SCCPGeneric_Response extends Response
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$Data = &$result;
|
$Data = &$result;
|
||||||
|
|
||||||
if ($all_key_ok) {
|
if ($all_key_ok) {
|
||||||
foreach ($set_name as $value_id) {
|
foreach ($set_name as $value_id) {
|
||||||
$Data = &$Data[$value_id];
|
$Data = &$Data[$value_id];
|
||||||
}
|
}
|
||||||
// Label converter in case labels and keys are different - not actually required.
|
// Label converter in case labels and keys are different
|
||||||
foreach ($_fields as $value_key => $value_id) {
|
foreach ($_fields as $value_key => $value_id) {
|
||||||
$Data[$value_id] = $_row[$value_key];
|
$Data[$value_id] = $_row[$value_key];
|
||||||
}
|
}
|
||||||
|
@ -421,7 +419,7 @@ class SCCPShowDevices_Response extends SCCPGeneric_Response
|
||||||
return $this->ConvertTableData(
|
return $this->ConvertTableData(
|
||||||
'Devices',
|
'Devices',
|
||||||
array('mac'),
|
array('mac'),
|
||||||
array('mac'=>'mac','address'=>'address','descr'=>'descr','regstate'=>'status',
|
array('mac'=>'name','address'=>'address','descr'=>'descr','regstate'=>'status',
|
||||||
'token'=>'token','act'=>'act', 'lines'=>'lines','nat'=>'nat','regtime'=>'regtime')
|
'token'=>'token','act'=>'act', 'lines'=>'lines','nat'=>'nat','regtime'=>'regtime')
|
||||||
);
|
);
|
||||||
// return $result;
|
// return $result;
|
||||||
|
@ -437,7 +435,9 @@ class SCCPShowDevice_Response extends SCCPGeneric_Response
|
||||||
public function getResult()
|
public function getResult()
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
foreach ($this->_events as $trow) {
|
foreach ($this->_events as $trow) {
|
||||||
|
dbug('keys are',$trow->getKeys());
|
||||||
$result = array_merge($result, $trow->getKeys());
|
$result = array_merge($result, $trow->getKeys());
|
||||||
}
|
}
|
||||||
$result['Buttons'] = $this->ConvertTableData(
|
$result['Buttons'] = $this->ConvertTableData(
|
||||||
|
|
|
@ -530,8 +530,59 @@ class aminterface
|
||||||
$result = array();
|
$result = array();
|
||||||
if ($this->_connect_state) {
|
if ($this->_connect_state) {
|
||||||
$_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPConfigMetaDataAction();
|
$_action = new \FreePBX\modules\Sccp_manager\aminterface\SCCPConfigMetaDataAction();
|
||||||
$_response = $this->send($_action);
|
$metadata = $this->send($_action)->getResult();
|
||||||
$result = $_response->getResult();
|
}
|
||||||
|
//return $result;
|
||||||
|
if ($metadata && array_key_exists("Version", $metadata)) {
|
||||||
|
$result["Version"] = $metadata["Version"];
|
||||||
|
$version_parts = explode(".", $metadata["Version"]);
|
||||||
|
$result["vCode"] = 0;
|
||||||
|
if ($version_parts[0] == "4") {
|
||||||
|
switch ($version_parts[1]) {
|
||||||
|
case "1":
|
||||||
|
$result["vCode"] = 410;
|
||||||
|
break;
|
||||||
|
case "2":
|
||||||
|
$result["vCode"] = 420;
|
||||||
|
break;
|
||||||
|
case 3. . .5:
|
||||||
|
if($version_parts[2] == "3"){
|
||||||
|
$result["vCode"] = 433;
|
||||||
|
} else {
|
||||||
|
$result["vCode"] = 430;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result["vCode"] = 400;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Revision got replaced by RevisionHash in 10404 (using the hash does not work) */
|
||||||
|
if (array_key_exists("Revision", $metadata)) {
|
||||||
|
if (base_convert($metadata["Revision"], 16, 10) == base_convert('702487a', 16, 10)) {
|
||||||
|
$result["vCode"] = 431;
|
||||||
|
}
|
||||||
|
if (base_convert($metadata["Revision"], 16, 10) >= "10403") {
|
||||||
|
$result["vCode"] = 431;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (array_key_exists("RevisionHash", $metadata)) {
|
||||||
|
$result["RevisionHash"] = $metadata["RevisionHash"];
|
||||||
|
} else {
|
||||||
|
$result["RevisionHash"] = '';
|
||||||
|
}
|
||||||
|
if (array_key_exists("RevisionNum", $metadata)) {
|
||||||
|
$result["RevisionNum"] = $metadata["RevisionNum"];
|
||||||
|
if ($metadata["RevisionNum"] >= "10403") { // new method, RevisionNum is incremental
|
||||||
|
$result["vCode"] = 432;
|
||||||
|
}
|
||||||
|
if ($metadata["RevisionNum"] >= "10491") { // new method, RevisionNum is incremental
|
||||||
|
$result["vCode"] = 433;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (array_key_exists("ConfigureEnabled", $metadata)) {
|
||||||
|
$result["futures"] = implode(';', $metadata["ConfigureEnabled"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,24 +117,27 @@ class srvinterface {
|
||||||
|
|
||||||
private function sccp_core_commands($params = array()) {
|
private function sccp_core_commands($params = array()) {
|
||||||
|
|
||||||
if ($this->ami_mode) {
|
if (!$this->ami_mode) {
|
||||||
if (!empty($params['cmd'])) {
|
return $this->oldinterface->sccp_core_commands($params);
|
||||||
switch ($params['cmd']) {
|
}
|
||||||
case 'reset_phone':
|
|
||||||
return $this->aminterface->sccpDeviceReset($params['name'], 'reset');
|
if (!empty($params['cmd'])) {
|
||||||
break;
|
switch ($params['cmd']) {
|
||||||
case 'restart_phone':
|
case 'reset_phone':
|
||||||
return $this->aminterface->sccpDeviceReset($params['name'], 'restart');
|
return $this->aminterface->sccpDeviceReset($params['name'], 'reset');
|
||||||
break;
|
break;
|
||||||
case 'reload_phone':
|
case 'restart_phone':
|
||||||
return $this->aminterface->sccpDeviceReset($params['name'], 'full');
|
return $this->aminterface->sccpDeviceReset($params['name'], 'restart');
|
||||||
break;
|
break;
|
||||||
case 'reset_token':
|
case 'reload_phone':
|
||||||
return $this->aminterface->sccpDeviceReset($params['name'], 'tokenack');
|
return $this->aminterface->sccpDeviceReset($params['name'], 'full');
|
||||||
break;
|
break;
|
||||||
case 'reload_line':
|
case 'reset_token':
|
||||||
|
return $this->aminterface->sccpDeviceReset($params['name'], 'tokenack');
|
||||||
|
break;
|
||||||
|
case 'reload_line':
|
||||||
// return $this->aminterface->sccpDeviceReset($params['name'], 'full');
|
// return $this->aminterface->sccpDeviceReset($params['name'], 'full');
|
||||||
break;
|
break;
|
||||||
// case 'get_version':
|
// case 'get_version':
|
||||||
// case 'sccp_reload':
|
// case 'sccp_reload':
|
||||||
// break;
|
// break;
|
||||||
|
@ -143,22 +146,20 @@ class srvinterface {
|
||||||
// case 'phone_call':
|
// case 'phone_call':
|
||||||
// case 'phone_message':
|
// case 'phone_message':
|
||||||
|
|
||||||
case 'get_softkey':
|
case 'get_softkey':
|
||||||
case 'get_device':
|
case 'get_device':
|
||||||
case 'get_hints':
|
case 'get_hints':
|
||||||
case 'get_dev_info':
|
case 'get_dev_info':
|
||||||
print_r($params);
|
print_r($params);
|
||||||
throw new \Exception("Invalid Class inside in the include folder" . $params['cmd']);
|
throw new \Exception("Invalid Class inside in the include folder" . $params['cmd']);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return $this->oldinterface->sccp_core_commands($params);
|
return $this->oldinterface->sccp_core_commands($params);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return $this->oldinterface->sccp_core_commands($params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sccp_getdevice_info($dev_id) {
|
public function sccp_getdevice_info($dev_id) {
|
||||||
|
@ -190,20 +191,11 @@ class srvinterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sccp_realtime_status() {
|
public function sccp_realtime_status() {
|
||||||
if (!$this->ami_mode) {
|
if ($this->ami_mode) {
|
||||||
return $this->oldinterface->sccp_realtime_status();
|
|
||||||
} else {
|
|
||||||
return $this->aminterface->getRealTimeStatus();
|
return $this->aminterface->getRealTimeStatus();
|
||||||
/* if (is_array($ast_out)) {
|
} else {
|
||||||
foreach ($ast_out as $aline) {
|
return $this->oldinterface->sccp_realtime_status();
|
||||||
if (strlen($aline) > 3) {
|
}
|
||||||
$ast_key = strstr(trim($aline), ' ', true);
|
|
||||||
$ast_res[$ast_key] = array('message' => $aline, 'status' => strpos($aline, 'connected') ? 'OK' : 'ERROR');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $ast_res;
|
|
||||||
*/ }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_compatible_sccp() {
|
public function get_compatible_sccp() {
|
||||||
|
@ -253,68 +245,10 @@ class srvinterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChanSCCPVersion() {
|
function getChanSCCPVersion() {
|
||||||
if (!$this->ami_mode) {
|
if ($this->ami_mode) {
|
||||||
return $this->oldinterface->getChanSCCPVersion();
|
return $this->aminterface->getSCCPVersion();
|
||||||
} else {
|
} else {
|
||||||
$result = array();
|
return $this->oldinterface->getChanSCCPVersion();
|
||||||
$metadata = $this->aminterface->getSCCPVersion();
|
|
||||||
|
|
||||||
if ($metadata && array_key_exists("Version", $metadata)) {
|
|
||||||
$result["Version"] = $metadata["Version"];
|
|
||||||
$version_parts = explode(".", $metadata["Version"]);
|
|
||||||
$result["vCode"] = 0;
|
|
||||||
if ($version_parts[0] == "4") {
|
|
||||||
switch ($version_parts[1]) {
|
|
||||||
case "1":
|
|
||||||
$result["vCode"] = 410;
|
|
||||||
break;
|
|
||||||
case "2":
|
|
||||||
$result["vCode"] = 420;
|
|
||||||
break;
|
|
||||||
case 3. . .5:
|
|
||||||
if($version_parts[2] == "3"){
|
|
||||||
$result["vCode"] = 433;
|
|
||||||
} else {
|
|
||||||
$result["vCode"] = 430;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$result["vCode"] = 400;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Revision got replaced by RevisionHash in 10404 (using the hash does not work) */
|
|
||||||
if (array_key_exists("Revision", $metadata)) {
|
|
||||||
if (base_convert($metadata["Revision"], 16, 10) == base_convert('702487a', 16, 10)) {
|
|
||||||
$result["vCode"] = 431;
|
|
||||||
}
|
|
||||||
if (base_convert($metadata["Revision"], 16, 10) >= "10403") {
|
|
||||||
$result["vCode"] = 431;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (array_key_exists("RevisionHash", $metadata)) {
|
|
||||||
$result["RevisionHash"] = $metadata["RevisionHash"];
|
|
||||||
} else {
|
|
||||||
$result["RevisionHash"] = '';
|
|
||||||
}
|
|
||||||
if (array_key_exists("RevisionNum", $metadata)) {
|
|
||||||
$result["RevisionNum"] = $metadata["RevisionNum"];
|
|
||||||
if ($metadata["RevisionNum"] >= "10403") { // new method, RevisionNum is incremental
|
|
||||||
$result["vCode"] = 432;
|
|
||||||
}
|
|
||||||
if ($metadata["RevisionNum"] >= "10491") { // new method, RevisionNum is incremental
|
|
||||||
$result["vCode"] = 433;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (array_key_exists("ConfigureEnabled", $metadata)) {
|
|
||||||
$result["futures"] = implode(';', $metadata["ConfigureEnabled"]);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
die_freepbx("Version information could not be retrieved from chan-sccp, via astman::SCCPConfigMetaData");
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue