|
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\Tokens; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* {@link https://tools.ietf.org/html/rfc1183}. |
|
20
|
|
|
*/ |
|
21
|
|
|
class RP implements RdataInterface |
|
22
|
|
|
{ |
|
23
|
|
|
use RdataTrait; |
|
24
|
|
|
|
|
25
|
|
|
const TYPE = 'RP'; |
|
26
|
|
|
const TYPE_CODE = 17; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $mailboxDomainName; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
private $txtDomainName; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getMailboxDomainName(): string |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->mailboxDomainName; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $mailboxDomainName |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function setMailboxDomainName(string $mailboxDomainName): void |
|
50
|
|
|
{ |
|
51
|
2 |
|
$this->mailboxDomainName = $mailboxDomainName; |
|
52
|
2 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getTxtDomainName(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->txtDomainName; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $txtDomainName |
|
64
|
|
|
*/ |
|
65
|
2 |
|
public function setTxtDomainName(string $txtDomainName): void |
|
66
|
|
|
{ |
|
67
|
2 |
|
$this->txtDomainName = $txtDomainName; |
|
68
|
2 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function toText(): string |
|
74
|
|
|
{ |
|
75
|
1 |
|
return sprintf('%s %s', $this->mailboxDomainName, $this->txtDomainName); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* {@inheritdoc} |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public function toWire(): string |
|
82
|
|
|
{ |
|
83
|
1 |
|
return self::encodeName($this->mailboxDomainName).self::encodeName($this->txtDomainName); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* {@inheritdoc} |
|
88
|
|
|
*/ |
|
89
|
|
|
public static function fromText(string $text): RdataInterface |
|
90
|
|
|
{ |
|
91
|
|
|
$rdata = explode(Tokens::SPACE, $text); |
|
92
|
|
|
$rp = new self(); |
|
93
|
|
|
$rp->setMailboxDomainName($rdata[0]); |
|
94
|
|
|
$rp->setTxtDomainName($rdata[1]); |
|
95
|
|
|
|
|
96
|
|
|
return $rp; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* {@inheritdoc} |
|
101
|
|
|
*/ |
|
102
|
1 |
|
public static function fromWire(string $rdata): RdataInterface |
|
103
|
|
|
{ |
|
104
|
1 |
|
$pos = strpos($rdata, "\0"); |
|
105
|
1 |
|
$mbox = substr($rdata, 0, $pos + 1); |
|
106
|
1 |
|
$txt = substr($rdata, $pos + 1); |
|
107
|
1 |
|
$rp = new self(); |
|
108
|
1 |
|
$rp->setMailboxDomainName(self::decodeName($mbox)); |
|
109
|
1 |
|
$rp->setTxtDomainName(self::decodeName($txt)); |
|
110
|
|
|
|
|
111
|
1 |
|
return $rp; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|