Event socket bug fix and more docs (#6823)
* Add documentation to methods. Use is_resource for added type detection * Allow connect to specify timeout in microseconds with default 30,000 * Update calling mechanism for event sockets * Update project for new singleton event sockets * remove unused variable * catch errors on closing the socket
This commit is contained in:
@@ -143,8 +143,8 @@
|
||||
save_gateway_xml();
|
||||
|
||||
//clear the cache
|
||||
$fp = event_socket_create();
|
||||
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
||||
$esl = event_socket::create();
|
||||
$hostname = trim(event_socket::api('switchname'));
|
||||
$cache = new cache;
|
||||
$cache->delete("configuration:sofia.conf:".$hostname);
|
||||
|
||||
|
||||
@@ -227,20 +227,16 @@
|
||||
save_gateway_xml();
|
||||
|
||||
//clear the cache
|
||||
$fp = event_socket_create();
|
||||
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
||||
$esl = event_socket::create();
|
||||
$hostname = trim(event_socket::api('switchname'));
|
||||
$cache = new cache;
|
||||
$cache->delete("configuration:sofia.conf:".$hostname);
|
||||
|
||||
//rescan the external profile to look for new or stopped gateways
|
||||
//create the event socket connection
|
||||
$fp = event_socket_create();
|
||||
$tmp_cmd = 'api sofia profile external rescan';
|
||||
$response = event_socket_request($fp, $tmp_cmd);
|
||||
unset($tmp_cmd);
|
||||
$esl = event_socket::create();
|
||||
$response = event_socket::api('sofia profile external rescan');
|
||||
usleep(1000);
|
||||
//close the connection
|
||||
fclose($fp);
|
||||
//clear the apply settings reminder
|
||||
$_SESSION["reload_xml"] = false;
|
||||
|
||||
|
||||
+14
-14
@@ -70,15 +70,15 @@
|
||||
$obj->delete($gateways);
|
||||
}
|
||||
case 'start':
|
||||
$fp = event_socket_create();
|
||||
if ($fp && permission_exists('gateway_edit')) {
|
||||
$esl = event_socket::create();
|
||||
if ($esl && permission_exists('gateway_edit')) {
|
||||
$obj = new gateways;
|
||||
$obj->start($gateways);
|
||||
}
|
||||
break;
|
||||
case 'stop':
|
||||
$fp = event_socket_create();
|
||||
if ($fp && permission_exists('gateway_edit')) {
|
||||
$esl = event_socket::create();
|
||||
if ($esl && permission_exists('gateway_edit')) {
|
||||
$obj = new gateways;
|
||||
$obj->stop($gateways);
|
||||
}
|
||||
@@ -90,19 +90,19 @@
|
||||
}
|
||||
|
||||
//connect to event socket
|
||||
$fp = event_socket_create();
|
||||
$esl = event_socket::create();
|
||||
|
||||
//gateway status function
|
||||
if (!function_exists('switch_gateway_status')) {
|
||||
function switch_gateway_status($gateway_uuid, $result_type = 'xml') {
|
||||
global $fp;
|
||||
if ($fp) {
|
||||
$fp = event_socket_create();
|
||||
$cmd = 'api sofia xmlstatus gateway '.$gateway_uuid;
|
||||
$response = trim(event_socket_request($fp, $cmd));
|
||||
global $esl;
|
||||
if ($esl->is_connected()) {
|
||||
$esl = event_socket::create();
|
||||
$cmd = 'sofia xmlstatus gateway '.$gateway_uuid;
|
||||
$response = trim(event_socket::api($cmd));
|
||||
if ($response == "Invalid Gateway!") {
|
||||
$cmd = 'api sofia xmlstatus gateway '.strtoupper($gateway_uuid);
|
||||
$response = trim(event_socket_request($fp, $cmd));
|
||||
$cmd = 'sofia xmlstatus gateway '.strtoupper($gateway_uuid);
|
||||
$response = trim(event_socket::api($cmd));
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
@@ -267,7 +267,7 @@
|
||||
echo "<th class='hide-sm-dn'>".$text['label-proxy']."</th>\n";
|
||||
echo th_order_by('context', $text['label-context'], $order_by, $order);
|
||||
echo th_order_by('register', $text['label-register'], $order_by, $order);
|
||||
if ($fp) {
|
||||
if ($esl->is_connected()) {
|
||||
echo "<th class='hide-sm-dn'>".$text['label-status']."</th>\n";
|
||||
if (permission_exists('gateway_edit')) {
|
||||
echo "<th class='center'>".$text['label-action']."</th>\n";
|
||||
@@ -316,7 +316,7 @@
|
||||
echo " <td>".escape($row["proxy"])."</td>\n";
|
||||
echo " <td>".escape($row["context"])."</td>\n";
|
||||
echo " <td>".ucwords(escape($row["register"]))."</td>\n";
|
||||
if ($fp) {
|
||||
if ($esl->is_connected()) {
|
||||
if ($row["enabled"] == "true") {
|
||||
$response = switch_gateway_status($row["gateway_uuid"]);
|
||||
if ($response == "Invalid Gateway!") {
|
||||
|
||||
@@ -110,23 +110,23 @@ if (!class_exists('gateways')) {
|
||||
|
||||
if (!empty($gateways) && is_array($gateways) && @sizeof($gateways) != 0) {
|
||||
//create the event socket connection
|
||||
$fp = event_socket_create();
|
||||
if ($fp) {
|
||||
$esl = event_socket::create();
|
||||
if ($esl->is_connected()) {
|
||||
//start gateways
|
||||
foreach ($gateways as $gateway_uuid => $gateway) {
|
||||
if ($gateway['enabled'] == 'true') {
|
||||
//start gateways
|
||||
foreach ($gateways as $gateway_uuid => $gateway) {
|
||||
if ($gateway['enabled'] == 'true') {
|
||||
$cmd = 'api sofia profile '.$gateway['profile'].' startgw '.$gateway_uuid;
|
||||
$cmd = 'sofia profile '.$gateway['profile'].' startgw '.$gateway_uuid;
|
||||
$responses[$gateway_uuid]['gateway'] = $gateway['name'];
|
||||
$responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd));
|
||||
$responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
|
||||
}
|
||||
}
|
||||
//old method used to start gateways
|
||||
//$cmd = 'api sofia profile '.$gateway['profile'].' rescan';
|
||||
//$cmd = 'sofia profile '.$gateway['profile'].' rescan';
|
||||
//$responses[$gateway_uuid]['gateway'] = $gateway['name'];
|
||||
//$responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd));
|
||||
//$responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,14 +198,14 @@ if (!class_exists('gateways')) {
|
||||
|
||||
if (!empty($gateways) && is_array($gateways) && @sizeof($gateways) != 0) {
|
||||
//create the event socket connection
|
||||
$fp = event_socket_create();
|
||||
if ($fp) {
|
||||
$esl = event_socket::create();
|
||||
if ($esl->is_connected()) {
|
||||
//stop gateways
|
||||
foreach ($gateways as $gateway_uuid => $gateway) {
|
||||
if ($gateway['enabled'] == 'true') {
|
||||
$cmd = 'api sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
|
||||
$cmd = 'sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
|
||||
$responses[$gateway_uuid]['gateway'] = $gateway['name'];
|
||||
$responses[$gateway_uuid]['message'] = trim(event_socket_request($fp, $cmd));
|
||||
$responses[$gateway_uuid]['message'] = trim(event_socket::api($cmd));
|
||||
}
|
||||
}
|
||||
//set message
|
||||
@@ -274,9 +274,7 @@ if (!class_exists('gateways')) {
|
||||
}
|
||||
|
||||
//create the event socket connection
|
||||
if (!isset($fp)) {
|
||||
$fp = event_socket_create();
|
||||
}
|
||||
$esl = event_socket::create();
|
||||
|
||||
//loop through gateways
|
||||
$x = 0;
|
||||
@@ -294,9 +292,9 @@ if (!class_exists('gateways')) {
|
||||
}
|
||||
|
||||
//send the api command to stop the gateway
|
||||
if ($fp) {
|
||||
$cmd = 'api sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
|
||||
$response = event_socket_request($fp, $cmd);
|
||||
if ($esl->is_connected()) {
|
||||
$cmd = 'sofia profile '.$gateway['profile'].' killgw '.$gateway_uuid;
|
||||
$response = event_socket::api($cmd);
|
||||
unset($cmd);
|
||||
}
|
||||
|
||||
@@ -320,20 +318,16 @@ if (!class_exists('gateways')) {
|
||||
save_gateway_xml();
|
||||
|
||||
//clear the cache
|
||||
if (!$fp) {
|
||||
$fp = event_socket_create();
|
||||
}
|
||||
if ($fp) {
|
||||
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
||||
$esl = event_socket::create();
|
||||
if ($esl->is_connected()) {
|
||||
$hostname = trim(event_socket::api('switchname'));
|
||||
$cache = new cache;
|
||||
$cache->delete("configuration:sofia.conf:".$hostname);
|
||||
}
|
||||
|
||||
//rescan the sip profile to look for new or stopped gateways
|
||||
if (!$fp) {
|
||||
$fp = event_socket_create();
|
||||
}
|
||||
if ($fp) {
|
||||
$esl = event_socket::create();
|
||||
if ($esl->is_connected()) {
|
||||
//get distinct profiles from gateways
|
||||
foreach ($gateways as $gateway) {
|
||||
$array[] = $gateway['profile'];
|
||||
@@ -342,13 +336,8 @@ if (!class_exists('gateways')) {
|
||||
|
||||
//send the api command to rescan each profile
|
||||
foreach ($profiles as $profile) {
|
||||
$cmd = 'api sofia profile '.$profile.' rescan';
|
||||
$response = event_socket_request($fp, $cmd);
|
||||
$response = event_socket::api("sofia profile $profile rescan");
|
||||
}
|
||||
unset($cmd);
|
||||
|
||||
//close the connection
|
||||
fclose($fp);
|
||||
}
|
||||
usleep(1000);
|
||||
|
||||
@@ -452,18 +441,16 @@ if (!class_exists('gateways')) {
|
||||
save_gateway_xml();
|
||||
|
||||
//clear the cache
|
||||
$fp = event_socket_create();
|
||||
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
||||
$esl = event_socket::create();
|
||||
$hostname = trim(event_socket::api('switchname'));
|
||||
$cache = new cache;
|
||||
$cache->delete("configuration:sofia.conf:".$hostname);
|
||||
|
||||
//create the event socket connection
|
||||
if (!$fp) {
|
||||
$fp = event_socket_create();
|
||||
}
|
||||
$esl = event_socket::create();
|
||||
|
||||
//rescan the sip profile to look for new or stopped gateways
|
||||
if ($fp) {
|
||||
if ($esl->is_connected()) {
|
||||
//get distinct profiles from gateways
|
||||
foreach ($gateways as $gateway) {
|
||||
$array[] = $gateway['profile'];
|
||||
@@ -472,13 +459,8 @@ if (!class_exists('gateways')) {
|
||||
|
||||
//send the api command to rescan each profile
|
||||
foreach ($profiles as $profile) {
|
||||
$cmd = 'api sofia profile '.$profile.' rescan';
|
||||
$response = event_socket_request($fp, $cmd);
|
||||
event_socket::api("sofia profile $profile rescan");
|
||||
}
|
||||
unset($cmd);
|
||||
|
||||
//close the connection
|
||||
fclose($fp);
|
||||
}
|
||||
usleep(1000);
|
||||
|
||||
@@ -585,8 +567,8 @@ if (!class_exists('gateways')) {
|
||||
save_gateway_xml();
|
||||
|
||||
//clear the cache
|
||||
$fp = event_socket_create();
|
||||
$hostname = trim(event_socket_request($fp, 'api switchname'));
|
||||
$esl = event_socket::create();
|
||||
$hostname = trim(event_socket::api('switchname'));
|
||||
$cache = new cache;
|
||||
$cache->delete("configuration:sofia.conf:".$hostname);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user