blob: da2ec6dccbf21f848060bb415fbab5b2c6ba73da [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001// Copyright (c) 2000-2004 Brian Wellington (bwelling@xbill.org)
2
3package org.xbill.DNS;
4
5import java.io.*;
6
7/**
8 * Name Authority Pointer Record - specifies rewrite rule, that when applied
9 * to an existing string will produce a new domain.
10 *
11 * @author Chuck Santos
12 */
13
14public class NAPTRRecord extends Record {
15
16private static final long serialVersionUID = 5191232392044947002L;
17
18private int order, preference;
19private byte [] flags, service, regexp;
20private Name replacement;
21
22NAPTRRecord() {}
23
24Record
25getObject() {
26 return new NAPTRRecord();
27}
28
29/**
30 * Creates an NAPTR Record from the given data
31 * @param order The order of this NAPTR. Records with lower order are
32 * preferred.
33 * @param preference The preference, used to select between records at the
34 * same order.
35 * @param flags The control aspects of the NAPTRRecord.
36 * @param service The service or protocol available down the rewrite path.
37 * @param regexp The regular/substitution expression.
38 * @param replacement The domain-name to query for the next DNS resource
39 * record, depending on the value of the flags field.
40 * @throws IllegalArgumentException One of the strings has invalid escapes
41 */
42public
43NAPTRRecord(Name name, int dclass, long ttl, int order, int preference,
44 String flags, String service, String regexp, Name replacement)
45{
46 super(name, Type.NAPTR, dclass, ttl);
47 this.order = checkU16("order", order);
48 this.preference = checkU16("preference", preference);
49 try {
50 this.flags = byteArrayFromString(flags);
51 this.service = byteArrayFromString(service);
52 this.regexp = byteArrayFromString(regexp);
53 }
54 catch (TextParseException e) {
55 throw new IllegalArgumentException(e.getMessage());
56 }
57 this.replacement = checkName("replacement", replacement);
58}
59
60void
61rrFromWire(DNSInput in) throws IOException {
62 order = in.readU16();
63 preference = in.readU16();
64 flags = in.readCountedString();
65 service = in.readCountedString();
66 regexp = in.readCountedString();
67 replacement = new Name(in);
68}
69
70void
71rdataFromString(Tokenizer st, Name origin) throws IOException {
72 order = st.getUInt16();
73 preference = st.getUInt16();
74 try {
75 flags = byteArrayFromString(st.getString());
76 service = byteArrayFromString(st.getString());
77 regexp = byteArrayFromString(st.getString());
78 }
79 catch (TextParseException e) {
80 throw st.exception(e.getMessage());
81 }
82 replacement = st.getName(origin);
83}
84
85/** Converts rdata to a String */
86String
87rrToString() {
88 StringBuffer sb = new StringBuffer();
89 sb.append(order);
90 sb.append(" ");
91 sb.append(preference);
92 sb.append(" ");
93 sb.append(byteArrayToString(flags, true));
94 sb.append(" ");
95 sb.append(byteArrayToString(service, true));
96 sb.append(" ");
97 sb.append(byteArrayToString(regexp, true));
98 sb.append(" ");
99 sb.append(replacement);
100 return sb.toString();
101}
102
103/** Returns the order */
104public int
105getOrder() {
106 return order;
107}
108
109/** Returns the preference */
110public int
111getPreference() {
112 return preference;
113}
114
115/** Returns flags */
116public String
117getFlags() {
118 return byteArrayToString(flags, false);
119}
120
121/** Returns service */
122public String
123getService() {
124 return byteArrayToString(service, false);
125}
126
127/** Returns regexp */
128public String
129getRegexp() {
130 return byteArrayToString(regexp, false);
131}
132
133/** Returns the replacement domain-name */
134public Name
135getReplacement() {
136 return replacement;
137}
138
139void
140rrToWire(DNSOutput out, Compression c, boolean canonical) {
141 out.writeU16(order);
142 out.writeU16(preference);
143 out.writeCountedString(flags);
144 out.writeCountedString(service);
145 out.writeCountedString(regexp);
146 replacement.toWire(out, null, canonical);
147}
148
149public Name
150getAdditionalName() {
151 return replacement;
152}
153
154}