Rewritten EPP connection code

This commit is contained in:
Pinga 2023-02-15 23:53:25 +02:00 committed by GitHub
parent fa17784456
commit 85ba677f5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

26
epp.php
View file

@ -1286,26 +1286,25 @@ class Registrar_Adapter_EPP extends Registrar_AdapterAbstract
public function read() public function read()
{ {
if (feof($this->socket)) { $hdr = stream_get_contents($this->socket, 4);
if ($hdr === false) {
throw new exception('Connection appears to have closed.'); throw new exception('Connection appears to have closed.');
} }
if (strlen($hdr) < 4) {
$hdr = @fread($this->socket, 4); throw new exception('Failed to read header from the connection.');
if (empty($hdr)) {
throw new exception('Error reading from server.');
} }
$unpacked = unpack('N', $hdr); $unpacked = unpack('N', $hdr);
$xml = fread($this->socket, ($unpacked[1] - 4)); $xml = fread($this->socket, ($unpacked[1] - 4));
$xml = preg_replace('/></', ">\n<", $xml); $xml = preg_replace('/></', ">\n<", $xml);
return $xml; return $xml;
} }
public function write($xml, $action = 'Unknown') public function write($xml)
{ {
@fwrite($this->socket, pack('N', (strlen($xml) + 4)) . $xml); if (fwrite($this->socket, pack('N', (strlen($xml) + 4)) . $xml) === false) {
$r = $this->read(); throw new exception('Error writing to the connection.');
$r = new SimpleXMLElement($r); }
$r = simplexml_load_string($this->readResponse());
if ($r->response->result->attributes()->code >= 2000) { if ($r->response->result->attributes()->code >= 2000) {
throw new exception($r->response->result->msg); throw new exception($r->response->result->msg);
} }
@ -1314,7 +1313,12 @@ class Registrar_Adapter_EPP extends Registrar_AdapterAbstract
public function disconnect() public function disconnect()
{ {
return @fclose($this->socket); $result = fclose($this->socket);
if (!$result) {
throw new exception('Error closing the connection.');
}
$this->socket = null;
return $result;
} }
function generateObjectPW($objType = 'none') function generateObjectPW($objType = 'none')