001: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS;
004:
005: import java.io.*;
006:
007: /**
008: * Start of Authority - describes properties of a zone.
009: *
010: * @author Brian Wellington
011: */
012:
013: public class SOARecord extends Record {
014:
015: private Name host, admin;
016: private long serial, refresh, retry, expire, minimum;
017:
018: SOARecord() {
019: }
020:
021: Record getObject() {
022: return new SOARecord();
023: }
024:
025: /**
026: * Creates an SOA Record from the given data
027: * @param host The primary name server for the zone
028: * @param admin The zone administrator's address
029: * @param serial The zone's serial number
030: * @param refresh The amount of time until a secondary checks for a new serial
031: * number
032: * @param retry The amount of time between a secondary's checks for a new
033: * serial number
034: * @param expire The amount of time until a secondary expires a zone
035: * @param minimum The minimum TTL for records in the zone
036: */
037: public SOARecord(Name name, int dclass, long ttl, Name host,
038: Name admin, long serial, long refresh, long retry,
039: long expire, long minimum) {
040: super (name, Type.SOA, dclass, ttl);
041: this .host = checkName("host", host);
042: this .admin = checkName("admin", admin);
043: this .serial = checkU32("serial", serial);
044: this .refresh = checkU32("refresh", refresh);
045: this .retry = checkU32("retry", retry);
046: this .expire = checkU32("expire", expire);
047: this .minimum = checkU32("minimum", minimum);
048: }
049:
050: void rrFromWire(DNSInput in) throws IOException {
051: host = new Name(in);
052: admin = new Name(in);
053: serial = in.readU32();
054: refresh = in.readU32();
055: retry = in.readU32();
056: expire = in.readU32();
057: minimum = in.readU32();
058: }
059:
060: void rdataFromString(Tokenizer st, Name origin) throws IOException {
061: host = st.getName(origin);
062: admin = st.getName(origin);
063: serial = st.getUInt32();
064: refresh = st.getTTLLike();
065: retry = st.getTTLLike();
066: expire = st.getTTLLike();
067: minimum = st.getTTLLike();
068: }
069:
070: /** Convert to a String */
071: String rrToString() {
072: StringBuffer sb = new StringBuffer();
073: sb.append(host);
074: sb.append(" ");
075: sb.append(admin);
076: if (Options.check("multiline")) {
077: sb.append(" (\n\t\t\t\t\t");
078: sb.append(serial);
079: sb.append("\t; serial\n\t\t\t\t\t");
080: sb.append(refresh);
081: sb.append("\t; refresh\n\t\t\t\t\t");
082: sb.append(retry);
083: sb.append("\t; retry\n\t\t\t\t\t");
084: sb.append(expire);
085: sb.append("\t; expire\n\t\t\t\t\t");
086: sb.append(minimum);
087: sb.append(" )\t; minimum");
088: } else {
089: sb.append(" ");
090: sb.append(serial);
091: sb.append(" ");
092: sb.append(refresh);
093: sb.append(" ");
094: sb.append(retry);
095: sb.append(" ");
096: sb.append(expire);
097: sb.append(" ");
098: sb.append(minimum);
099: }
100: return sb.toString();
101: }
102:
103: /** Returns the primary name server */
104: public Name getHost() {
105: return host;
106: }
107:
108: /** Returns the zone administrator's address */
109: public Name getAdmin() {
110: return admin;
111: }
112:
113: /** Returns the zone's serial number */
114: public long getSerial() {
115: return serial;
116: }
117:
118: /** Returns the zone refresh interval */
119: public long getRefresh() {
120: return refresh;
121: }
122:
123: /** Returns the zone retry interval */
124: public long getRetry() {
125: return retry;
126: }
127:
128: /** Returns the time until a secondary expires a zone */
129: public long getExpire() {
130: return expire;
131: }
132:
133: /** Returns the minimum TTL for records in the zone */
134: public long getMinimum() {
135: return minimum;
136: }
137:
138: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
139: host.toWire(out, c, canonical);
140: admin.toWire(out, c, canonical);
141: out.writeU32(serial);
142: out.writeU32(refresh);
143: out.writeU32(retry);
144: out.writeU32(expire);
145: out.writeU32(minimum);
146: }
147:
148: }
|