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

centralnic/issues#3886: consolidate trs_epp

parent 4e0c7d5c
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
* @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('Net/EPP/Protocol.php');
$GLOBALS['Net_EPP_Client_Version'] = '0.0.5'; $GLOBALS['Net_EPP_Client_Version'] = '0.0.6';
/** /**
* A simple client class for the Extensible Provisioning Protocol (EPP) * A simple client class for the Extensible Provisioning Protocol (EPP)
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
* @var resource the socket resource, once connected * @var resource the socket resource, once connected
*/ */
public $socket; public $socket;
/** /**
* @var bool do output more debug messages * @var bool do output more debug messages
*/ */
...@@ -59,7 +58,7 @@ ...@@ -59,7 +58,7 @@
$GLOBALS['debug'] = $debug; $GLOBALS['debug'] = $debug;
$this->socket = null; $this->socket = null;
} }
/** /**
* Establishes a connect to the server * Establishes a connect to the server
* This method establishes the connection to the server. If the connection was * This method establishes the connection to the server. If the connection was
...@@ -67,24 +66,26 @@ ...@@ -67,24 +66,26 @@
* frame which is sent by the server upon connection. If connection fails, then * frame which is sent by the server upon connection. If connection fails, then
* an exception with a message explaining the error will be thrown and handled * an exception with a message explaining the error will be thrown and handled
* in the calling code. * in the calling code.
* @param string $host the hostname * @param string $host the hostname
* @param integer $port the TCP port * @param integer $port the TCP port
* @param integer $timeout the timeout in seconds * @param integer $timeout the timeout in seconds
* @param boolean $ssl whether to connect using SSL * @param boolean $ssl whether to connect using SSL
* @param resource $context a stream resource to use when setting up the socket connection * @param resource $context a stream resource to use when setting up the socket connection
*@param string $protocol whether to use TLS or SSL
* @throws Exception on connection errors * @throws Exception on connection errors
* @return a string containing the server <greeting> * @return a string containing the server <greeting>
*/ */
public function connect($host, $port = 700, $timeout = 1, $ssl = true, $context = null) public function connect($host, $port = 700, $timeout = 1, $ssl = true, $context = null, $protocol = 'tls')
{ {
if ($this->debug) { if ($this->debug) {
syslog(LOG_INFO, "in connect"); syslog(LOG_INFO, "in connect");
} }
$target = sprintf('%s://%s:%d', ($ssl === true ? 'tls' : 'tcp'), $host, $port);
$target = sprintf('%s://%s:%d', ($ssl === true ? $protocol : 'tcp'), $host, $port);
if ($this->debug) { if ($this->debug) {
syslog(LOG_INFO, "connecting to {$target}"); syslog(LOG_INFO, "connecting to {$target}");
} }
if (is_resource($context)) { if (is_resource($context)) {
if ($this->debug) { if ($this->debug) {
syslog(LOG_INFO, "using your provided context resource"); syslog(LOG_INFO, "using your provided context resource");
...@@ -93,7 +94,6 @@ ...@@ -93,7 +94,6 @@
} else { } else {
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT); $result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
} }
if (is_resource($result)) { if (is_resource($result)) {
if ($errno == 0) { if ($errno == 0) {
if ($this->debug) { if ($this->debug) {
...@@ -117,14 +117,13 @@ ...@@ -117,14 +117,13 @@
} }
} }
// Set stream timeout // 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)"); throw new Exception("Failed to set timeout on socket: $errstr (code $errno)");
} }
$this->timeout = $timeout; $this->timeout = $timeout;
$GLOBALS['timeout'] = $timeout; $GLOBALS['timeout'] = $timeout;
// Set blocking // 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)"); throw new Exception("Failed to set blocking on socket: $errstr (code $errno)");
......
...@@ -22,9 +22,11 @@ ...@@ -22,9 +22,11 @@
$this->command->appendChild($this->payload); $this->command->appendChild($this->payload);
} }
}
function addclTRID($id) {
$this->clTRID = $this->createElement('clTRID'); $this->clTRID = $this->createElement('clTRID');
$this->clTRID->appendChild($this->createTextNode('')); $this->clTRID->appendChild($this->createTextNode($id));
$this->body->appendChild($this->clTRID); $this->body->appendChild($this->clTRID);
} }
...@@ -42,23 +44,32 @@ ...@@ -42,23 +44,32 @@
return $element; return $element;
} }
function createObjectPropertyElement($name) { function createObjectPropertyElement($name, $type=NULL) {
$ns_type = isset($type) ? $type : $this->type;
$ns = !empty($ns_type) ? $ns_type.':'.$name : $name;
return $this->createElementNS( return $this->createElementNS(
Net_EPP_ObjectSpec::xmlns($this->type), Net_EPP_ObjectSpec::xmlns($ns_type), $ns
$this->type.':'.$name
); );
} }
function createExtensionElement($ext, $command) { function createExtension() {
$this->extension = $this->createElement('extension'); $this->extension = $this->createElement('extension');
$this->body->appendChild($this->extension); $this->body->appendChild($this->extension);
}
/**
* Creates an extension element with the option of specifying a custom namespace
* @param $ext
* @param $command
* @param null $version *
*/
function createExtensionElement($ext, $command, $version=null) {
$this->extension->payload = $this->createElementNS( $this->extension->payload = $this->createElementNS(
Net_EPP_ObjectSpec::xmlns($ext), Net_EPP_ObjectSpec::xmlns($version !== null ? $version : $ext),
$ext.':'.$command $ext.':'.$command
); );
$this->extension->appendChild($this->extension->payload); $this->extension->appendChild($this->extension->payload);
} }
} }
?> ?>
<?php
/**
* @package Net_EPP
*/
class Net_EPP_Frame_Command_Check_Contact extends Net_EPP_Frame_Command_Check {
function __construct() {
parent::__construct('contact');
}
}
?>
...@@ -26,5 +26,15 @@ ...@@ -26,5 +26,15 @@
$this->command->appendChild($this->svcs); $this->command->appendChild($this->svcs);
} }
function addExtension($exts) {
$extensions = $this->createElement('svcExtension');
foreach ($exts as $ext) {
$ext_el = $this->createObjectPropertyElement('extURI');
$ext_el->appendChild($this->createTextNode(Net_EPP_ObjectSpec::xmlns($ext)));
$extensions->appendChild($ext_el);
}
$this->svcs->appendChild($extensions);
}
} }
?> ?>
<?php
/**
* @package Net_EPP
*/
class Net_EPP_Frame_Command_Logout extends Net_EPP_Frame_Command {
function __construct() {
parent::__construct('logout');
}
}
?>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
/** /**
* @package Net_EPP * @package Net_EPP
*/ */
class Net_EPP_Frame_Greeting extends Net_EPP_Frame { final class Net_EPP_Frame_Greeting extends Net_EPP_Frame {
function __construct() { function __construct() {
parent::__construct('greeting'); parent::__construct('greeting');
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
/** /**
* @package Net_EPP * @package Net_EPP
*/ */
class Net_EPP_Frame_Hello extends Net_EPP_Frame { final class Net_EPP_Frame_Hello extends Net_EPP_Frame {
function __construct() { function __construct() {
parent::__construct('hello'); parent::__construct('hello');
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
/** /**
* @package Net_EPP * @package Net_EPP
*/ */
class Net_EPP_Frame_Response extends Net_EPP_Frame { final class Net_EPP_Frame_Response extends Net_EPP_Frame {
function __construct() { function __construct() {
parent::__construct('response'); parent::__construct('response');
} }
......
...@@ -26,6 +26,61 @@ ...@@ -26,6 +26,61 @@
'id' => 'id', 'id' => 'id',
'schema' => 'urn:ietf:params:xml:ns:rgp-1.0 rgp-1.0.xsd', 'schema' => 'urn:ietf:params:xml:ns:rgp-1.0 rgp-1.0.xsd',
), ),
'launch' => array(
'xmlns' => 'urn:ietf:params:xml:ns:launch-1.0',
'id' => 'id',
'schema' => 'urn:ar:params:xml:ns:launch-1.0 launch-1.0.xsd',
),
'idn' => array(
'xmlns' => 'urn:ietf:params:xml:ns:idn-1.0',
'id' => 'id',
'schema' => 'urn:ar:params:xml:ns:idn-1.0 idn-1.0.xsd',
),
'tmch' => array(
'xmlns' => 'urn:ar:params:xml:ns:tmch-1.0',
'id' => 'id',
'schema' => 'urn:ar:params:xml:ns:tmch-1.0 tmch-1.0.xsd',
),
'application' => array(
'xmlns' => 'urn:ar:params:xml:ns:application-1.0',
'id' => 'id',
'schema' => 'urn:ar:params:xml:ns:application-1.0 application-1.0.xsd',
),
'price' => array(
'xmlns' => 'urn:ar:params:xml:ns:price-1.0',
'id' => 'id',
'schema' => 'urn:ar:params:xml:ns:price-1.0 price-1.0.xsd',
),
'asia' => array(
'xmlns' => 'urn:ar:params:xml:ns:asia-1.0',
'id' => 'id',
'schema' => 'urn:ar:params:xml:ns:asia-1.0 asia-1.0.xsd',
),
'signedMark' => array(
'xmlns' => 'urn:ietf:params:xml:ns:signedMark-1.0',
'id' => 'domain',
'schema' => 'urn:ietf:params:xml:ns:signedMark-1.0 signedMark-1.0.xsd',
),
'fee' => array(
'xmlns' => 'urn:ietf:params:xml:ns:fee-0.5',
'id' => 'domain',
'schema' => 'urn:ietf:params:xml:ns:fee-0.5 fee-0.5.xsd',
),
'fee_23' => array(
'xmlns' => 'urn:ietf:params:xml:ns:fee-0.23',
'id' => 'domain',
'schema' => 'urn:ietf:params:xml:ns:fee-0.23 fee-0.23.xsd',
),
'allocationToken' => array(
'xmlns' => 'urn:ietf:params:xml:ns:allocationToken-1.0',
'id' => 'domain',
'schema' => 'urn:ietf:params:xml:ns:allocationToken-1.0 allocationToken-1.0.xsd',
),
'auxcontact' => array(
'xmlns' => 'urn:ietf:params:xml:ns:auxcontact-0.1',
'id' => 'domain',
'schema' => 'urn:ietf:params:xml:ns:auxcontact-0.1 auxcontact-1.0.xsd',
),
); );
static function id($object) { static function id($object) {
......
...@@ -41,7 +41,7 @@ class Net_EPP_Protocol ...@@ -41,7 +41,7 @@ class Net_EPP_Protocol
while (!$info['timed_out'] && !feof($socket)) { while (!$info['timed_out'] && !feof($socket)) {
//make sure we don't wait to long //make sure we don't wait to long
if ($timeout_time < microtime(true)) { if (($time_end - $time_start) > 10000000) {
$time_diff = microtime(true) - $time_start; $time_diff = microtime(true) - $time_start;
throw new exception("Timeout reading from EPP server after $time_diff seconds"); throw new exception("Timeout reading from EPP server after $time_diff seconds");
} }
...@@ -71,6 +71,7 @@ class Net_EPP_Protocol ...@@ -71,6 +71,7 @@ class Net_EPP_Protocol
$time_diff = (microtime(true) - $time_start) * 1000; $time_diff = (microtime(true) - $time_start) * 1000;
syslog(LOG_INFO, "returning after {$time_diff} ms"); syslog(LOG_INFO, "returning after {$time_diff} ms");
} }
return $result; return $result;
} }
...@@ -115,6 +116,7 @@ class Net_EPP_Protocol ...@@ -115,6 +116,7 @@ class Net_EPP_Protocol
if ($info['timed_out']) { if ($info['timed_out']) {
throw new Exception('Timeout while writing data to socket'); throw new Exception('Timeout while writing data to socket');
} }
return $pos; return $pos;
} }
...@@ -135,7 +137,6 @@ class Net_EPP_Protocol ...@@ -135,7 +137,6 @@ class Net_EPP_Protocol
if ($GLOBALS['debug']) { if ($GLOBALS['debug']) {
syslog(LOG_INFO, "read header successfully containing ".var_dump($hdr)); syslog(LOG_INFO, "read header successfully containing ".var_dump($hdr));
} }
// Unpack first 4 bytes which is our length // Unpack first 4 bytes which is our length
$unpacked = unpack('N', $hdr); $unpacked = unpack('N', $hdr);
$length = $unpacked[1]; $length = $unpacked[1];
...@@ -158,12 +159,10 @@ class Net_EPP_Protocol ...@@ -158,12 +159,10 @@ class Net_EPP_Protocol
public static function sendFrame($socket, $xml) public static function sendFrame($socket, $xml)
{ {
$length = strlen($xml) + 4; $length = strlen($xml) + 4;
if ($GLOBALS['debug']) { if ($GLOBALS['debug']) {
syslog(LOG_INFO, "length of the header is ${length} about to write ${xml}"); syslog(LOG_INFO, "length of the header is ${length} about to write ${xml}");
} }
// Grab XML length & add on 4 bytes for the counter // Grab XML length & add on 4 bytes for the counter
$res = Net_EPP_Protocol::_fwrite_nb($socket, pack('N', $length) . $xml, $length); $res = Net_EPP_Protocol::_fwrite_nb($socket, pack('N', $length) . $xml, $length);
// Check our write matches // Check our write matches
if ($length != $res) { if ($length != $res) {
......
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