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

centralnic/issues#3769: fix syntax

parent b3d8431e
<?php <?php
/* EPP Client class for PHP, Copyright 2005 CentralNic Ltd /* EPP Client class for PHP, Copyright 2005 CentralNic Ltd
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/** /**
* A simple client class for the Extensible Provisioning Protocol (EPP) * A simple client class for the Extensible Provisioning Protocol (EPP)
* @package Net_EPP * @package Net_EPP
* @version 0.0.4 * @version 0.0.4
* @author Gavin Brown <gavin.brown@nospam.centralnic.com> * @author Gavin Brown <gavin.brown@nospam.centralnic.com>
* @revision $Id: Client.php,v 1.13 2010/10/21 11:55:07 gavin Exp $ * @revision $Id: Client.php,v 1.13 2010/10/21 11:55:07 gavin Exp $
*/ */
require_once('Protocol.php');
require_once('Protocol.php');
$GLOBALS['Net_EPP_Client_Version'] = '0.0.5';
$GLOBALS['Net_EPP_Client_Version'] = '0.0.5';
/**
/** * A simple client class for the Extensible Provisioning Protocol (EPP)
* A simple client class for the Extensible Provisioning Protocol (EPP) * @package Net_EPP
* @package Net_EPP */
*/ class Net_EPP_Client
class Net_EPP_Client { {
/** /**
* @var resource the socket resource, once connected * @var resource the socket resource, once connected
*/ */
var $socket; public $socket;
/** /**
* @var bool do output more debug messages * @var bool do output more debug messages
*/ */
var $debug; public $debug;
/** /**
* @var integer timeout to wait on commands * @var integer timeout to wait on commands
*/ */
var $timeout; public $timeout;
/** /**
* constructor set initialize various objects * constructor set initialize various objects
* @param boolean set debugging on * @param boolean set debugging on
*/ */
public function __construct($debug = false) { public function __construct($debug = false)
$this->debug = $debug; {
$GLOBALS['debug']=$debug; $this->debug = $debug;
$this->socket = NULL; $GLOBALS['debug'] = $debug;
} $this->socket = null;
}
/**
* Establishes a connect to the server /**
* This method establishes the connection to the server. If the connection was * Establishes a connect to the server
* established, then this method will call getFrame() and return the EPP <greeting> * This method establishes the connection to the server. If the connection was
* frame which is sent by the server upon connection. If connection fails, then * established, then this method will call getFrame() and return the EPP <greeting>
* an exception with a message explaining the error will be thrown and handled * frame which is sent by the server upon connection. If connection fails, then
* in the calling code. * an exception with a message explaining the error will be thrown and handled
* @param string $host the hostname * in the calling code.
* @param integer $port the TCP port * @param string $host the hostname
* @param integer $timeout the timeout in seconds * @param integer $port the TCP port
* @param boolean $ssl whether to connect using SSL * @param integer $timeout the timeout in seconds
* @param resource $context a stream resource to use when setting up the socket connection * @param boolean $ssl whether to connect using SSL
* @throws Exception on connection errors * @param resource $context a stream resource to use when setting up the socket connection
* @return a string containing the server <greeting> * @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)
$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, "in connect");
if (is_resource($context)) { }
if($this->debug) debug_log("using your provided context resource"); $target = sprintf('%s://%s:%d', ($ssl === true ? 'tls' : 'tcp'), $host, $port);
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context); if ($this->debug) {
syslog(LOG_INFO, "connecting to {$target}");
} else { }
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
} if (is_resource($context)) {
if ($this->debug) {
if (is_resource($result)) { syslog(LOG_INFO, "using your provided context resource");
if ($errno == 0) { }
if($this->debug){ $result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context);
$socketmeta = stream_get_meta_data($result); } else {
if (isset($socketmeta['crypto'])) { $result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
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"); }
} else {
debug_log("socket opened without crypt"); if (is_resource($result)) {
} if ($errno == 0) {
} if ($this->debug) {
// Set our socket $socketmeta = stream_get_meta_data($result);
$this->socket = $result; if (isset($socketmeta['crypto'])) {
} 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{ } else {
throw new Exception("non errono 0 retrieved from socket connection: {$errno}"); syslog(LOG_INFO, "socket opened without crypt");
} }
} else { }
if($result === FALSE && $errno == 0){ // Set our socket
throw new Exception("Connection could not be opened due to socket problem. Reasons can be unmatched peer name, tls not supported..."); $this->socket = $result;
} } else {
else { throw new Exception("non errono 0 retrieved from socket connection: {$errno}");
throw new Exception("Connection could not be opened: $errno $errstr"); }
} } else {
} 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 {
// Set stream timeout throw new Exception("Connection could not be opened: $errno $errstr");
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; // Set stream timeout
if (!stream_set_timeout($this->socket, $timeout)) {
// Set blocking throw new Exception("Failed to set timeout on socket: $errstr (code $errno)");
if (!stream_set_blocking($this->socket,0)) { }
throw new Exception("Failed to set blocking on socket: $errstr (code $errno)"); $this->timeout = $timeout;
} $GLOBALS['timeout'] = $timeout;
if($this->debug) debug_log("trying to get frame from server");
return $this->getFrame(); // Set blocking
} if (!stream_set_blocking($this->socket, 0)) {
throw new Exception("Failed to set blocking on socket: $errstr (code $errno)");
/** }
* Get an EPP frame from the server. if ($this->debug) {
* This retrieves a frame from the server. Since the connection is blocking, this syslog(LOG_INFO, "trying to get frame from server");
* method will wait until one becomes available. If the connection has been broken, }
* this method will return a string containing the XML from the server return $this->getFrame();
* @throws Exception on frame errors }
* @return a string containing the frame
*/ /**
function getFrame() { * Get an EPP frame from the server.
return Net_EPP_Protocol::getFrame($this->socket); * This retrieves a frame from the server. Since the connection is blocking, this
} * method will wait until one becomes available. If the connection has been broken,
* this method will return a string containing the XML from the server
/** * @throws Exception on frame errors
* Send an XML frame to the server. * @return a string containing the frame
* This method sends an EPP frame to the server. */
* @param string the XML data to send public function getFrame()
* @throws Exception when it doesn't complete the write to the socket {
* @return boolean the result of the fwrite() operation return Net_EPP_Protocol::getFrame($this->socket);
*/ }
function sendFrame($xml) {
return Net_EPP_Protocol::sendFrame($this->socket, $xml); /**
} * Send an XML frame to the server.
* This method sends an EPP frame to the server.
/** * @param string the XML data to send
* a wrapper around sendFrame() and getFrame() * @throws Exception when it doesn't complete the write to the socket
* @param string $xml the frame to send to the server * @return boolean the result of the fwrite() operation
* @throws Exception when it doesn't complete the write to the socket */
* @return string the frame returned by the server, or an error object public function sendFrame($xml)
*/ {
function request($xml) { return Net_EPP_Protocol::sendFrame($this->socket, $xml);
$res = $this->sendFrame($xml); }
return $this->getFrame();
} /**
* a wrapper around sendFrame() and getFrame()
/** * @param string $xml the frame to send to the server
* Close the connection. * @throws Exception when it doesn't complete the write to the socket
* This method closes the connection to the server. Note that the * @return string the frame returned by the server, or an error object
* EPP specification indicates that clients should send a <logout> */
* command before ending the session. public function request($xml)
* @return boolean the result of the fclose() operation {
*/ $res = $this->sendFrame($xml);
function disconnect() { return $this->getFrame();
return @fclose($this->socket); }
}
/**
/** * Close the connection.
* ping the connection to check that it's up * This method closes the connection to the server. Note that the
* @return boolean * EPP specification indicates that clients should send a <logout>
*/ * command before ending the session.
function ping() { * @return boolean the result of the fclose() operation
return (!is_resource($this->socket) || feof($this->socket) ? false : true); */
} public function disconnect()
{
} return @fclose($this->socket);
}
?>
/**
* ping the connection to check that it's up
* @return boolean
*/
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