1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Rdata; |
15
|
|
|
|
16
|
|
|
use Badcow\DNS\Parser\StringIterator; |
17
|
|
|
use Badcow\DNS\Parser\Tokens; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see https://tools.ietf.org/html/rfc1035#section-3.3.2 |
21
|
|
|
*/ |
22
|
|
|
class HINFO implements RdataInterface |
23
|
|
|
{ |
24
|
1 |
|
use RdataTrait; |
25
|
|
|
|
26
|
|
|
const TYPE = 'HINFO'; |
27
|
|
|
const TYPE_CODE = 13; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string|null |
31
|
|
|
*/ |
32
|
|
|
private $cpu; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var string|null |
36
|
|
|
*/ |
37
|
|
|
private $os; |
38
|
|
|
|
39
|
15 |
|
public function setCpu(?string $cpu): void |
40
|
|
|
{ |
41
|
15 |
|
$this->cpu = $cpu; |
42
|
15 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return string |
46
|
|
|
*/ |
47
|
4 |
|
public function getCpu(): ?string |
48
|
|
|
{ |
49
|
4 |
|
return $this->cpu; |
50
|
|
|
} |
51
|
|
|
|
52
|
15 |
|
public function setOs(?string $os): void |
53
|
|
|
{ |
54
|
15 |
|
$this->os = $os; |
55
|
15 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
4 |
|
public function getOs(): ?string |
61
|
|
|
{ |
62
|
4 |
|
return $this->os; |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
public function toText(): string |
66
|
|
|
{ |
67
|
4 |
|
return sprintf('"%s" "%s"', $this->cpu ?? '', $this->os ?? ''); |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
public function toWire(): string |
71
|
|
|
{ |
72
|
1 |
|
return $this->toText(); |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
public function fromWire(string $rdata, int &$offset = 0, ?int $rdLength = null): void |
76
|
|
|
{ |
77
|
1 |
|
$this->fromText(substr($rdata, $offset, $rdLength ?? strlen($rdata))); |
78
|
1 |
|
$offset += $rdLength; |
79
|
1 |
|
} |
80
|
|
|
|
81
|
2 |
|
public function fromText(string $text): void |
82
|
|
|
{ |
83
|
2 |
|
$string = new StringIterator($text); |
84
|
2 |
|
$this->setCpu(self::extractText($string)); |
85
|
2 |
|
$this->setOs(self::extractText($string)); |
86
|
2 |
|
} |
87
|
|
|
|
88
|
2 |
|
private static function extractText(StringIterator $string): string |
89
|
|
|
{ |
90
|
2 |
|
$txt = new StringIterator(); |
91
|
|
|
|
92
|
2 |
|
if ($string->is(Tokens::DOUBLE_QUOTES)) { |
93
|
2 |
|
TXT::handleTxt($string, $txt); |
94
|
2 |
|
$string->next(); |
95
|
|
|
} else { |
96
|
1 |
|
while ($string->isNot(Tokens::SPACE) && $string->valid()) { |
97
|
1 |
|
$txt->append($string->current()); |
98
|
1 |
|
$string->next(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
2 |
|
if ($string->is(Tokens::SPACE)) { |
103
|
2 |
|
$string->next(); |
104
|
|
|
} |
105
|
|
|
|
106
|
2 |
|
return (string) $txt; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|