Home | History | Annotate | Download | only in DNS
      1 // Copyright (c) 1999-2004 Brian Wellington (bwelling (at) xbill.org)
      2 
      3 package org.xbill.DNS;
      4 
      5 import java.io.*;
      6 
      7 /**
      8  * Start of Authority - describes properties of a zone.
      9  *
     10  * @author Brian Wellington
     11  */
     12 
     13 public class SOARecord extends Record {
     14 
     15 private static final long serialVersionUID = 1049740098229303931L;
     16 
     17 private Name host, admin;
     18 private long serial, refresh, retry, expire, minimum;
     19 
     20 SOARecord() {}
     21 
     22 Record
     23 getObject() {
     24 	return new SOARecord();
     25 }
     26 
     27 /**
     28  * Creates an SOA Record from the given data
     29  * @param host The primary name server for the zone
     30  * @param admin The zone administrator's address
     31  * @param serial The zone's serial number
     32  * @param refresh The amount of time until a secondary checks for a new serial
     33  * number
     34  * @param retry The amount of time between a secondary's checks for a new
     35  * serial number
     36  * @param expire The amount of time until a secondary expires a zone
     37  * @param minimum The minimum TTL for records in the zone
     38 */
     39 public
     40 SOARecord(Name name, int dclass, long ttl, Name host, Name admin,
     41 	  long serial, long refresh, long retry, long expire, long minimum)
     42 {
     43 	super(name, Type.SOA, dclass, ttl);
     44 	this.host = checkName("host", host);
     45 	this.admin = checkName("admin", admin);
     46 	this.serial = checkU32("serial", serial);
     47 	this.refresh = checkU32("refresh", refresh);
     48 	this.retry = checkU32("retry", retry);
     49 	this.expire = checkU32("expire", expire);
     50 	this.minimum = checkU32("minimum", minimum);
     51 }
     52 
     53 void
     54 rrFromWire(DNSInput in) throws IOException {
     55 	host = new Name(in);
     56 	admin = new Name(in);
     57 	serial = in.readU32();
     58 	refresh = in.readU32();
     59 	retry = in.readU32();
     60 	expire = in.readU32();
     61 	minimum = in.readU32();
     62 }
     63 
     64 void
     65 rdataFromString(Tokenizer st, Name origin) throws IOException {
     66 	host = st.getName(origin);
     67 	admin = st.getName(origin);
     68 	serial = st.getUInt32();
     69 	refresh = st.getTTLLike();
     70 	retry = st.getTTLLike();
     71 	expire = st.getTTLLike();
     72 	minimum = st.getTTLLike();
     73 }
     74 
     75 /** Convert to a String */
     76 String
     77 rrToString() {
     78 	StringBuffer sb = new StringBuffer();
     79 	sb.append(host);
     80 	sb.append(" ");
     81 	sb.append(admin);
     82 	if (Options.check("multiline")) {
     83 		sb.append(" (\n\t\t\t\t\t");
     84 		sb.append(serial);
     85 		sb.append("\t; serial\n\t\t\t\t\t");
     86 		sb.append(refresh);
     87 		sb.append("\t; refresh\n\t\t\t\t\t");
     88 		sb.append(retry);
     89 		sb.append("\t; retry\n\t\t\t\t\t");
     90 		sb.append(expire);
     91 		sb.append("\t; expire\n\t\t\t\t\t");
     92 		sb.append(minimum);
     93 		sb.append(" )\t; minimum");
     94 	} else {
     95 		sb.append(" ");
     96 		sb.append(serial);
     97 		sb.append(" ");
     98 		sb.append(refresh);
     99 		sb.append(" ");
    100 		sb.append(retry);
    101 		sb.append(" ");
    102 		sb.append(expire);
    103 		sb.append(" ");
    104 		sb.append(minimum);
    105 	}
    106 	return sb.toString();
    107 }
    108 
    109 /** Returns the primary name server */
    110 public Name
    111 getHost() {
    112 	return host;
    113 }
    114 
    115 /** Returns the zone administrator's address */
    116 public Name
    117 getAdmin() {
    118 	return admin;
    119 }
    120 
    121 /** Returns the zone's serial number */
    122 public long
    123 getSerial() {
    124 	return serial;
    125 }
    126 
    127 /** Returns the zone refresh interval */
    128 public long
    129 getRefresh() {
    130 	return refresh;
    131 }
    132 
    133 /** Returns the zone retry interval */
    134 public long
    135 getRetry() {
    136 	return retry;
    137 }
    138 
    139 /** Returns the time until a secondary expires a zone */
    140 public long
    141 getExpire() {
    142 	return expire;
    143 }
    144 
    145 /** Returns the minimum TTL for records in the zone */
    146 public long
    147 getMinimum() {
    148 	return minimum;
    149 }
    150 
    151 void
    152 rrToWire(DNSOutput out, Compression c, boolean canonical) {
    153 	host.toWire(out, c, canonical);
    154 	admin.toWire(out, c, canonical);
    155 	out.writeU32(serial);
    156 	out.writeU32(refresh);
    157 	out.writeU32(retry);
    158 	out.writeU32(expire);
    159 	out.writeU32(minimum);
    160 }
    161 
    162 }
    163