Skip to content

Commit

Permalink
mass update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Nov 11, 2023
1 parent d44e380 commit c05d027
Show file tree
Hide file tree
Showing 24 changed files with 298 additions and 67 deletions.
4 changes: 3 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
stopOnRisky="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnIncompleteTests="true"
>
<testsuites>
Expand All @@ -26,7 +27,8 @@
</testsuite>
</testsuites>
<php>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<env name="APP_ENV" value="testing"/>
<env name="DEFAULT_TIMEOUT" value="3.5"/>
</php>
</phpunit>
9 changes: 4 additions & 5 deletions src/Abstracts/AbstractResourceRecordType.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ protected function parseMessage(): void
'Response header length is invalid'
);
}

[
'type' => $type,
'class' => $class,
Expand Down Expand Up @@ -201,11 +200,11 @@ public function getHeader(): string
}

/**
* @return string
* @inheritdoc
*/
public function getMessage(): string
public function getMessage(): PacketMessageInterface
{
return $this->getHeader() . $this->getRData();
return $this->message;
}

/**
Expand Down Expand Up @@ -315,7 +314,7 @@ public function toArray(): array
'host' => $this->getName(),
'class' => $this->getClass()->getName(),
'ttl' => $this->getTTL(),
'type' => $this->getType(),
'type' => $this->getType()->getName(),
'value' => $this->getValue(),
];
}
Expand Down
8 changes: 8 additions & 0 deletions src/Interfaces/Packet/PacketHeaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,14 @@ public function withARCount(int $ar) : static;
*/
public function withANCount(int $an) : static;

/**
* With NS count
*
* @param int $ns
* @return $this
*/
public function withNSCount(int $ns) : static;

/**
* With QD Count
* @param int $qd
Expand Down
7 changes: 7 additions & 0 deletions src/Interfaces/Packet/PacketResourceRecordsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public function getRecords(): array;
*/
public function getFilteredType(string $type, bool $single = false) : null|array|ResourceRecordTypeInterface;

/**
* Return array records
* @uses ResourceRecordTypeInterface::toArray()
* @return array<array>
*/
public function toArray() : array;

/**
* @return Traversable<ResourceRecordTypeInterface>
*/
Expand Down
9 changes: 5 additions & 4 deletions src/Interfaces/ResourceRecord/ResourceRecordTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public function getOffsetPosition() : int;
public function getHeader() : string;

/**
* Get message raw response answer data
* Get message raw all response answer data
*
* @return string
* @return PacketMessageInterface
*/
public function getMessage(): string;
public function getMessage(): PacketMessageInterface;

/**
* The dns name
Expand Down Expand Up @@ -141,7 +141,8 @@ public function getQueryMessage() : string;
/**
* Return array data
*
* @return array
* @return array like dns_get_record()
* @see \dns_get_record()
*/
public function toArray() : array;
}
11 changes: 11 additions & 0 deletions src/Packet/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,17 @@ public function withANCount(int $an): static
return $obj;
}

/**
* @inheritdoc
*/
public function withNSCount(int $ns): static
{
$obj = clone $this;
$obj->nscount = $ns;
$obj->message = null;
return $obj;
}

/**
* @inheritdoc
*/
Expand Down
1 change: 1 addition & 0 deletions src/Packet/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public function __serialize(): array
* @param int $type
* @param int $class
* @return Question
* @noinspection PhpDocMissingThrowsInspection
*/
public static function fromFilteredResponse(
string $name,
Expand Down
10 changes: 10 additions & 0 deletions src/Packet/Records.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use ArrayAccess\DnsRecord\Interfaces\ResourceRecord\ResourceRecordTypeInterface;
use ArrayIterator;
use Traversable;
use function array_map;
use function array_values;
use function md5;
use function serialize;
use function strtoupper;
Expand Down Expand Up @@ -86,6 +88,14 @@ public function getFilteredType(string $type, bool $single = false) : null|array
return $result === [] ? null : $result;
}

/**
* @inheritdoc
*/
public function toArray(): array
{
return array_map(static fn ($e) => $e->toArray(), array_values($this->getRecords()));
}

/**
* @inheritdoc
*/
Expand Down
8 changes: 5 additions & 3 deletions src/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public function createQueryOpcode(
$class = trim($class?:IN::NAME)?:IN::NAME;
$class = Lookup::resourceClass($class);
$type = Lookup::resourceType($type);
$isOpt = $type->getName() === OPT::TYPE;
$typeName = $type->getName();
$isOpt = $typeName === OPT::TYPE;
if ($isOpt) { // if is OPT fallback to A
$type = 'A';
}
Expand All @@ -165,12 +166,13 @@ public function createQueryOpcode(
}
$dns = new DnsServerStorage(...$ss);
}

$header = Header::createQueryHeader($opcode, null, $adFlag, $cdFlag, $recurse);
$requestData = new RequestData(
Header::createQueryHeader($opcode, null, $adFlag, $cdFlag, $recurse),
$header,
$dns,
$question
);

if ($isOpt || $dnsSec) {
$requestData
->getAdditionalRecords()
Expand Down
20 changes: 11 additions & 9 deletions src/ResourceRecord/RRTypes/CERT.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use ArrayAccess\DnsRecord\Abstracts\AbstractResourceRecordType;
use function array_values;
use function base64_encode;
use function substr;

/**
Expand Down Expand Up @@ -56,26 +57,27 @@ protected function parseRData(string $message, int $rdataOffset): void
//
// copy the certificate
//
$this->certificate = substr($this->rData, 5, $this->rdLength - 5);
$this->certificate = base64_encode(substr($this->rData, 5, $this->rdLength - 5));
}

public function getFormat(): ?int
public function getFormat(): int
{
return $this->format??null;
return $this->format;
}

public function getKeyTag(): ?int
public function getKeyTag(): int
{
return $this->keyTag??null;
return $this->keyTag;
}

public function getAlgorithm(): ?string
public function getAlgorithm(): string
{
return $this->algorithm??null;
return $this->algorithm;
}

public function getCertificate(): ?string
public function getCertificate(): string
{
return $this->certificate??null;
return $this->certificate;
}
}
// @todo add toArray()
17 changes: 12 additions & 5 deletions src/ResourceRecord/RRTypes/CNAME.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ class CNAME extends AbstractResourceRecordType
{
const TYPE = 'CNAME';

protected string $cname;

/**
* @inheritdoc
*/
protected function parseRData(string $message, int $rdataOffset): void
{
$this->cname = Buffer::readLabel($message, $rdataOffset);
$this->value = Buffer::readLabel($message, $rdataOffset);
}

public function getCname(): string
/**
* @inheritdoc
*/
public function toArray(): array
{
return $this->cname;
return [
'host' => $this->getName(),
'class' => $this->getClass()->getName(),
'ttl' => $this->getTTL(),
'type' => $this->getType()->getName(),
'target' => $this->getValue(),
];
}
}
1 change: 1 addition & 0 deletions src/ResourceRecord/RRTypes/DNSKEY.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ protected function parseRData(string $message, int $rdataOffset): void
$this->zoneSep = ((int)$flags[15]) === 1;
}
}
// @todo add toArray()
25 changes: 25 additions & 0 deletions src/ResourceRecord/RRTypes/HINFO.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,29 @@ protected function parseRData(string $message, int $rdataOffset): void
$this->rdLength - strlen($this->cpu)
);
}

public function getCpu(): string
{
return $this->cpu;
}

public function getOs(): string
{
return $this->os;
}

/**
* @inheritdoc
*/
public function toArray(): array
{
return [
'host' => $this->getName(),
'class' => $this->getClass()->getName(),
'ttl' => $this->getTTL(),
'type' => $this->getType()->getName(),
'cpu' => $this->getCpu(),
'os' => $this->getOs(),
];
}
}
49 changes: 49 additions & 0 deletions src/ResourceRecord/RRTypes/IXFR.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

namespace ArrayAccess\DnsRecord\ResourceRecord\RRTypes;

use ArrayAccess\DnsRecord\Abstracts\AbstractResourceRecordType;
use ArrayAccess\DnsRecord\Interfaces\ResourceRecord\ResourceRecordMetaTypeInterface;

/**
* A IXFR Query format - RFC1995 Section &
*
* +---------------------------------------------------+
* Header | OPCODE=SQUERY |
* +---------------------------------------------------+
* Question | QNAME=JAIN.AD.JP., QCLASS=IN, QTYPE=IXFR |
* +---------------------------------------------------+
* Answer | <empty> |
* +---------------------------------------------------+
* Authority | JAIN.AD.JP. IN SOA serial=1 |
* +---------------------------------------------------+
* Additional | <empty> |
* +---------------------------------------------------+
*
* IXFR Response Format
*
* +---------------------------------------------------+
* Header | OPCODE=SQUERY, RESPONSE |
* +---------------------------------------------------+
* Question | QNAME=JAIN.AD.JP., QCLASS=IN, QTYPE=IXFR |
* +---------------------------------------------------+
* Answer | JAIN.AD.JP. IN SOA serial=3 |
* | JAIN.AD.JP. IN NS NS.JAIN.AD.JP. |
* | NS.JAIN.AD.JP. IN A 133.69.136.1 |
* | JAIN-BB.JAIN.AD.JP. IN A 133.69.136.3 |
* | JAIN-BB.JAIN.AD.JP. IN A 192.41.197.2 |
* | JAIN.AD.JP. IN SOA serial=3 |
* +---------------------------------------------------+
* Authority | <empty> |
* +---------------------------------------------------+
* Additional | <empty> |
* +---------------------------------------------------+
*
* @link https://datatracker.ietf.org/doc/html/rfc1995#section-7
*/
class IXFR extends AbstractResourceRecordType implements ResourceRecordMetaTypeInterface
{
const TYPE = 'IXFR';
}
// @todo add completion()
1 change: 1 addition & 0 deletions src/ResourceRecord/RRTypes/MG.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ protected function parseRData(string $message, int $rdataOffset): void
$this->value = Buffer::readLabel($message, $rdataOffset);
}
}
// @todo add toArray()
1 change: 1 addition & 0 deletions src/ResourceRecord/RRTypes/MR.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ protected function parseRData(string $message, int $rdataOffset): void
$this->value = Buffer::readLabel($message, $rdataOffset);
}
}
// @todo add toArray()
15 changes: 15 additions & 0 deletions src/ResourceRecord/RRTypes/MX.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,19 @@ public function getExchange(): string
{
return $this->exchange;
}

/**
* @inheritdoc
*/
public function toArray(): array
{
return [
'host' => $this->getName(),
'class' => $this->getClass()->getName(),
'ttl' => $this->getTTL(),
'type' => $this->getType()->getName(),
'pri' => $this->getPreference(),
'target' => $this->getExchange(),
];
}
}
14 changes: 14 additions & 0 deletions src/ResourceRecord/RRTypes/NS.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ protected function parseRData(string $message, int $rdataOffset): void
{
$this->value = Buffer::readLabel($message, $rdataOffset);
}

/**
* @inheritdoc
*/
public function toArray(): array
{
return [
'host' => $this->getName(),
'class' => $this->getClass()->getName(),
'ttl' => $this->getTTL(),
'type' => $this->getType()->getName(),
'target' => $this->getValue(),
];
}
}
Loading

0 comments on commit c05d027

Please sign in to comment.