Unverified Commit 81b354bd authored by Nathan Van Overloop's avatar Nathan Van Overloop
Browse files

centralnic/issues#3769: fix syntax

parent b3d8431e
......@@ -23,7 +23,6 @@
* @author Gavin Brown <gavin.brown@nospam.centralnic.com>
* @revision $Id: Client.php,v 1.13 2010/10/21 11:55:07 gavin Exp $
*/
require_once('Protocol.php');
$GLOBALS['Net_EPP_Client_Version'] = '0.0.5';
......@@ -32,31 +31,33 @@
* A simple client class for the Extensible Provisioning Protocol (EPP)
* @package Net_EPP
*/
class Net_EPP_Client {
class Net_EPP_Client
{
/**
* @var resource the socket resource, once connected
*/
var $socket;
public $socket;
/**
* @var bool do output more debug messages
*/
var $debug;
public $debug;
/**
* @var integer timeout to wait on commands
*/
var $timeout;
public $timeout;
/**
* constructor set initialize various objects
* @param boolean set debugging on
*/
public function __construct($debug = false) {
public function __construct($debug = false)
{
$this->debug = $debug;
$GLOBALS['debug']=$debug;
$this->socket = NULL;
$GLOBALS['debug'] = $debug;
$this->socket = null;
}
/**
......@@ -74,57 +75,63 @@
* @throws Exception on connection errors
* @return a string containing the server <greeting>
*/
function connect($host, $port=700, $timeout=1, $ssl=true, $context=NULL) {
if($this->debug) debug_log("in connect");
public function connect($host, $port = 700, $timeout = 1, $ssl = true, $context = null)
{
if ($this->debug) {
syslog(LOG_INFO, "in connect");
}
$target = sprintf('%s://%s:%d', ($ssl === true ? 'tls' : 'tcp'), $host, $port);
if($this->debug) debug_log("connecting to {$target}");
if ($this->debug) {
syslog(LOG_INFO, "connecting to {$target}");
}
if (is_resource($context)) {
if($this->debug) debug_log("using your provided context resource");
if ($this->debug) {
syslog(LOG_INFO, "using your provided context resource");
}
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
} else {
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
}
if (is_resource($result)) {
if ($errno == 0) {
if($this->debug){
if ($this->debug) {
$socketmeta = stream_get_meta_data($result);
if (isset($socketmeta['crypto'])) {
debug_log("socket opened with protocol ".$socketmeta['crypto']['protocol'].", cipher ".$socketmeta['crypto']['cipher_name'].", ".$socketmeta['crypto']['cipher_bits']." bits ".$socketmeta['crypto']['cipher_version'],"Connection made");
syslog(LOG_NOTICE, "socket opened with protocol ".$socketmeta['crypto']['protocol'].", cipher ".$socketmeta['crypto']['cipher_name'].", ".$socketmeta['crypto']['cipher_bits']." bits ".$socketmeta['crypto']['cipher_version'], "Connection made");
} else {
debug_log("socket opened without crypt");
syslog(LOG_INFO, "socket opened without crypt");
}
}
// Set our socket
$this->socket = $result;
}
else{
} else {
throw new Exception("non errono 0 retrieved from socket connection: {$errno}");
}
} else {
if($result === FALSE && $errno == 0){
if ($result === false && $errno == 0) {
throw new Exception("Connection could not be opened due to socket problem. Reasons can be unmatched peer name, tls not supported...");
}
else {
} else {
throw new Exception("Connection could not be opened: $errno $errstr");
}
}
// Set stream timeout
if (!stream_set_timeout($this->socket,$timeout)) {
if (!stream_set_timeout($this->socket, $timeout)) {
throw new Exception("Failed to set timeout on socket: $errstr (code $errno)");
}
$this->timeout=$timeout;
$GLOBALS['timeout']=$timeout;
$this->timeout = $timeout;
$GLOBALS['timeout'] = $timeout;
// Set blocking
if (!stream_set_blocking($this->socket,0)) {
if (!stream_set_blocking($this->socket, 0)) {
throw new Exception("Failed to set blocking on socket: $errstr (code $errno)");
}
if($this->debug) debug_log("trying to get frame from server");
if ($this->debug) {
syslog(LOG_INFO, "trying to get frame from server");
}
return $this->getFrame();
}
......@@ -136,7 +143,8 @@
* @throws Exception on frame errors
* @return a string containing the frame
*/
function getFrame() {
public function getFrame()
{
return Net_EPP_Protocol::getFrame($this->socket);
}
......@@ -147,7 +155,8 @@
* @throws Exception when it doesn't complete the write to the socket
* @return boolean the result of the fwrite() operation
*/
function sendFrame($xml) {
public function sendFrame($xml)
{
return Net_EPP_Protocol::sendFrame($this->socket, $xml);
}
......@@ -157,7 +166,8 @@
* @throws Exception when it doesn't complete the write to the socket
* @return string the frame returned by the server, or an error object
*/
function request($xml) {
public function request($xml)
{
$res = $this->sendFrame($xml);
return $this->getFrame();
}
......@@ -169,7 +179,8 @@
* command before ending the session.
* @return boolean the result of the fclose() operation
*/
function disconnect() {
public function disconnect()
{
return @fclose($this->socket);
}
......@@ -177,10 +188,8 @@
* ping the connection to check that it's up
* @return boolean
*/
function ping() {
public function ping()
{
return (!is_resource($this->socket) || feof($this->socket) ? false : true);
}
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment