1 // Copyright (c) 2000-2004 Brian Wellington (bwelling (at) xbill.org) 2 3 package org.xbill.DNS; 4 5 import 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 14 public class NAPTRRecord extends Record { 15 16 private static final long serialVersionUID = 5191232392044947002L; 17 18 private int order, preference; 19 private byte [] flags, service, regexp; 20 private Name replacement; 21 22 NAPTRRecord() {} 23 24 Record 25 getObject() { 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 */ 42 public 43 NAPTRRecord(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 60 void 61 rrFromWire(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 70 void 71 rdataFromString(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 */ 86 String 87 rrToString() { 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 */ 104 public int 105 getOrder() { 106 return order; 107 } 108 109 /** Returns the preference */ 110 public int 111 getPreference() { 112 return preference; 113 } 114 115 /** Returns flags */ 116 public String 117 getFlags() { 118 return byteArrayToString(flags, false); 119 } 120 121 /** Returns service */ 122 public String 123 getService() { 124 return byteArrayToString(service, false); 125 } 126 127 /** Returns regexp */ 128 public String 129 getRegexp() { 130 return byteArrayToString(regexp, false); 131 } 132 133 /** Returns the replacement domain-name */ 134 public Name 135 getReplacement() { 136 return replacement; 137 } 138 139 void 140 rrToWire(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 149 public Name 150 getAdditionalName() { 151 return replacement; 152 } 153 154 } 155