aboutsummaryrefslogtreecommitdiff
path: root/src/org/xbill/DNS/X25Record.java
blob: 1349a1e767496b35e6c822c47974833ce1ff6382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)

package org.xbill.DNS;

import java.io.*;

/**
 * X25 - identifies the PSDN (Public Switched Data Network) address in the
 * X.121 numbering plan associated with a name.
 *
 * @author Brian Wellington
 */

public class X25Record extends Record {

private static final long serialVersionUID = 4267576252335579764L;

private byte [] address;

X25Record() {}

Record
getObject() {
	return new X25Record();
}

private static final byte []
checkAndConvertAddress(String address) {
	int length = address.length();
	byte [] out = new byte [length];
	for (int i = 0; i < length; i++) {
		char c = address.charAt(i);
		if (!Character.isDigit(c))
			return null;
		out[i] = (byte) c;
	}
	return out;
}

/**
 * Creates an X25 Record from the given data
 * @param address The X.25 PSDN address.
 * @throws IllegalArgumentException The address is not a valid PSDN address.
 */
public
X25Record(Name name, int dclass, long ttl, String address) {
	super(name, Type.X25, dclass, ttl);
	this.address = checkAndConvertAddress(address);
	if (this.address == null) {
		throw new IllegalArgumentException("invalid PSDN address " +
						   address);
	}
}

void
rrFromWire(DNSInput in) throws IOException {
	address = in.readCountedString();
}

void
rdataFromString(Tokenizer st, Name origin) throws IOException {
	String addr = st.getString();
	this.address = checkAndConvertAddress(addr);
	if (this.address == null)
		throw st.exception("invalid PSDN address " + addr);
}

/**
 * Returns the X.25 PSDN address.
 */
public String
getAddress() {
	return byteArrayToString(address, false);
}

void
rrToWire(DNSOutput out, Compression c, boolean canonical) {
	out.writeCountedString(address);
}

String
rrToString() {
	return byteArrayToString(address, true);
}

}