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 @@
* @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');
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)
......@@ -38,7 +38,6 @@
* @var resource the socket resource, once connected
*/
public $socket;
/**
* @var bool do output more debug messages
*/
......@@ -72,15 +71,17 @@
* @param integer $timeout the timeout in seconds
* @param boolean $ssl whether to connect using SSL
* @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
* @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) {
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) {
syslog(LOG_INFO, "connecting to {$target}");
}
......@@ -93,7 +94,6 @@
} else {
$result = stream_socket_client($target, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT);
}
if (is_resource($result)) {
if ($errno == 0) {
if ($this->debug) {
......@@ -117,7 +117,6 @@
}
}
// Set stream timeout
if (!stream_set_timeout($this->socket, $timeout)) {
throw new Exception("Failed to set timeout on socket: $errstr (code $errno)");
......
......@@ -22,9 +22,11 @@
$this->command->appendChild($this->payload);
}
}
function addclTRID($id) {
$this->clTRID = $this->createElement('clTRID');
$this->clTRID->appendChild($this->createTextNode(''));
$this->clTRID->appendChild($this->createTextNode($id));
$this->body->appendChild($this->clTRID);
}
......@@ -42,23 +44,32 @@
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(
Net_EPP_ObjectSpec::xmlns($this->type),
$this->type.':'.$name
Net_EPP_ObjectSpec::xmlns($ns_type), $ns
);
}
function createExtensionElement($ext, $command) {
function createExtension() {
$this->extension = $this->createElement('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(
Net_EPP_ObjectSpec::xmlns($ext),
Net_EPP_ObjectSpec::xmlns($version !== null ? $version : $ext),
$ext.':'.$command
);
$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 @@
$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 @@
/**
* @package Net_EPP
*/
class Net_EPP_Frame_Greeting extends Net_EPP_Frame {
final class Net_EPP_Frame_Greeting extends Net_EPP_Frame {
function __construct() {
parent::__construct('greeting');
......
......@@ -3,7 +3,7 @@
/**
* @package Net_EPP
*/
class Net_EPP_Frame_Hello extends Net_EPP_Frame {
final class Net_EPP_Frame_Hello extends Net_EPP_Frame {
function __construct() {
parent::__construct('hello');
}
......
......@@ -3,7 +3,7 @@
/**
* @package Net_EPP
*/
class Net_EPP_Frame_Response extends Net_EPP_Frame {
final class Net_EPP_Frame_Response extends Net_EPP_Frame {
function __construct() {
parent::__construct('response');
}
......
......@@ -26,6 +26,61 @@
'id' => 'id',
'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) {
......
......@@ -41,7 +41,7 @@ class Net_EPP_Protocol
while (!$info['timed_out'] && !feof($socket)) {
//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;
throw new exception("Timeout reading from EPP server after $time_diff seconds");
}
......@@ -71,6 +71,7 @@ class Net_EPP_Protocol
$time_diff = (microtime(true) - $time_start) * 1000;
syslog(LOG_INFO, "returning after {$time_diff} ms");
}
return $result;
}
......@@ -116,6 +117,7 @@ class Net_EPP_Protocol
throw new Exception('Timeout while writing data to socket');
}
return $pos;
}
......@@ -135,7 +137,6 @@ class Net_EPP_Protocol
if ($GLOBALS['debug']) {
syslog(LOG_INFO, "read header successfully containing ".var_dump($hdr));
}
// Unpack first 4 bytes which is our length
$unpacked = unpack('N', $hdr);
$length = $unpacked[1];
......@@ -158,12 +159,10 @@ class Net_EPP_Protocol
public static function sendFrame($socket, $xml)
{
$length = strlen($xml) + 4;
if ($GLOBALS['debug']) {
syslog(LOG_INFO, "length of the header is ${length} about to write ${xml}");
}
// Grab XML length & add on 4 bytes for the counter
$res = Net_EPP_Protocol::_fwrite_nb($socket, pack('N', $length) . $xml, $length);
// Check our write matches
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