• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
2 
3 package org.xbill.DNS;
4 
5 import java.io.*;
6 
7 /**
8  * X25 - identifies the PSDN (Public Switched Data Network) address in the
9  * X.121 numbering plan associated with a name.
10  *
11  * @author Brian Wellington
12  */
13 
14 public class X25Record extends Record {
15 
16 private static final long serialVersionUID = 4267576252335579764L;
17 
18 private byte [] address;
19 
X25Record()20 X25Record() {}
21 
22 Record
getObject()23 getObject() {
24 	return new X25Record();
25 }
26 
27 private static final byte []
checkAndConvertAddress(String address)28 checkAndConvertAddress(String address) {
29 	int length = address.length();
30 	byte [] out = new byte [length];
31 	for (int i = 0; i < length; i++) {
32 		char c = address.charAt(i);
33 		if (!Character.isDigit(c))
34 			return null;
35 		out[i] = (byte) c;
36 	}
37 	return out;
38 }
39 
40 /**
41  * Creates an X25 Record from the given data
42  * @param address The X.25 PSDN address.
43  * @throws IllegalArgumentException The address is not a valid PSDN address.
44  */
45 public
X25Record(Name name, int dclass, long ttl, String address)46 X25Record(Name name, int dclass, long ttl, String address) {
47 	super(name, Type.X25, dclass, ttl);
48 	this.address = checkAndConvertAddress(address);
49 	if (this.address == null) {
50 		throw new IllegalArgumentException("invalid PSDN address " +
51 						   address);
52 	}
53 }
54 
55 void
rrFromWire(DNSInput in)56 rrFromWire(DNSInput in) throws IOException {
57 	address = in.readCountedString();
58 }
59 
60 void
rdataFromString(Tokenizer st, Name origin)61 rdataFromString(Tokenizer st, Name origin) throws IOException {
62 	String addr = st.getString();
63 	this.address = checkAndConvertAddress(addr);
64 	if (this.address == null)
65 		throw st.exception("invalid PSDN address " + addr);
66 }
67 
68 /**
69  * Returns the X.25 PSDN address.
70  */
71 public String
getAddress()72 getAddress() {
73 	return byteArrayToString(address, false);
74 }
75 
76 void
rrToWire(DNSOutput out, Compression c, boolean canonical)77 rrToWire(DNSOutput out, Compression c, boolean canonical) {
78 	out.writeCountedString(address);
79 }
80 
81 String
rrToString()82 rrToString() {
83 	return byteArrayToString(address, true);
84 }
85 
86 }
87