001: // Copyright (c) 2000-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS;
004:
005: import java.io.*;
006:
007: /**
008: * Name Authority Pointer Record - specifies rewrite rule, that when applied
009: * to an existing string will produce a new domain.
010: *
011: * @author Chuck Santos
012: */
013:
014: public class NAPTRRecord extends Record {
015:
016: private int order, preference;
017: private byte[] flags, service, regexp;
018: private Name replacement;
019:
020: NAPTRRecord() {
021: }
022:
023: Record getObject() {
024: return new NAPTRRecord();
025: }
026:
027: /**
028: * Creates an NAPTR Record from the given data
029: * @param order The order of this NAPTR. Records with lower order are
030: * preferred.
031: * @param preference The preference, used to select between records at the
032: * same order.
033: * @param flags The control aspects of the NAPTRRecord.
034: * @param service The service or protocol available down the rewrite path.
035: * @param regexp The regular/substitution expression.
036: * @param replacement The domain-name to query for the next DNS resource
037: * record, depending on the value of the flags field.
038: * @throws IllegalArgumentException One of the strings has invalid escapes
039: */
040: public NAPTRRecord(Name name, int dclass, long ttl, int order,
041: int preference, String flags, String service,
042: String regexp, Name replacement) {
043: super (name, Type.NAPTR, dclass, ttl);
044: this .order = checkU16("order", order);
045: this .preference = checkU16("preference", preference);
046: try {
047: this .flags = byteArrayFromString(flags);
048: this .service = byteArrayFromString(service);
049: this .regexp = byteArrayFromString(regexp);
050: } catch (TextParseException e) {
051: throw new IllegalArgumentException(e.getMessage());
052: }
053: this .replacement = checkName("replacement", replacement);
054: }
055:
056: void rrFromWire(DNSInput in) throws IOException {
057: order = in.readU16();
058: preference = in.readU16();
059: flags = in.readCountedString();
060: service = in.readCountedString();
061: regexp = in.readCountedString();
062: replacement = new Name(in);
063: }
064:
065: void rdataFromString(Tokenizer st, Name origin) throws IOException {
066: order = st.getUInt16();
067: preference = st.getUInt16();
068: try {
069: flags = byteArrayFromString(st.getString());
070: service = byteArrayFromString(st.getString());
071: regexp = byteArrayFromString(st.getString());
072: } catch (TextParseException e) {
073: throw st.exception(e.getMessage());
074: }
075: replacement = st.getName(origin);
076: }
077:
078: /** Converts rdata to a String */
079: String rrToString() {
080: StringBuffer sb = new StringBuffer();
081: sb.append(order);
082: sb.append(" ");
083: sb.append(preference);
084: sb.append(" ");
085: sb.append(byteArrayToString(flags, true));
086: sb.append(" ");
087: sb.append(byteArrayToString(service, true));
088: sb.append(" ");
089: sb.append(byteArrayToString(regexp, true));
090: sb.append(" ");
091: sb.append(replacement);
092: return sb.toString();
093: }
094:
095: /** Returns the order */
096: public int getOrder() {
097: return order;
098: }
099:
100: /** Returns the preference */
101: public int getPreference() {
102: return preference;
103: }
104:
105: /** Returns flags */
106: public String getFlags() {
107: return byteArrayToString(flags, false);
108: }
109:
110: /** Returns service */
111: public String getService() {
112: return byteArrayToString(service, false);
113: }
114:
115: /** Returns regexp */
116: public String getRegexp() {
117: return byteArrayToString(regexp, false);
118: }
119:
120: /** Returns the replacement domain-name */
121: public Name getReplacement() {
122: return replacement;
123: }
124:
125: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
126: out.writeU16(order);
127: out.writeU16(preference);
128: out.writeCountedString(flags);
129: out.writeCountedString(service);
130: out.writeCountedString(regexp);
131: replacement.toWire(out, null, canonical);
132: }
133:
134: public Name getAdditionalName() {
135: return replacement;
136: }
137:
138: }
|