001: // Copyright (c) 1999-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS;
004:
005: import java.io.*;
006: import java.util.*;
007:
008: /**
009: * Next name - this record contains the following name in an ordered list
010: * of names in the zone, and a set of types for which records exist for
011: * this name. The presence of this record in a response signifies a
012: * failed query for data in a DNSSEC-signed zone.
013: *
014: * @author Brian Wellington
015: */
016:
017: public class NXTRecord extends Record {
018:
019: private Name next;
020: private BitSet bitmap;
021:
022: NXTRecord() {
023: }
024:
025: Record getObject() {
026: return new NXTRecord();
027: }
028:
029: /**
030: * Creates an NXT Record from the given data
031: * @param next The following name in an ordered list of the zone
032: * @param bitmap The set of type for which records exist at this name
033: */
034: public NXTRecord(Name name, int dclass, long ttl, Name next,
035: BitSet bitmap) {
036: super (name, Type.NXT, dclass, ttl);
037: this .next = checkName("next", next);
038: this .bitmap = bitmap;
039: }
040:
041: void rrFromWire(DNSInput in) throws IOException {
042: next = new Name(in);
043: bitmap = new BitSet();
044: int bitmapLength = in.remaining();
045: for (int i = 0; i < bitmapLength; i++) {
046: int t = in.readU8();
047: for (int j = 0; j < 8; j++)
048: if ((t & (1 << (7 - j))) != 0)
049: bitmap.set(i * 8 + j);
050: }
051: }
052:
053: void rdataFromString(Tokenizer st, Name origin) throws IOException {
054: next = st.getName(origin);
055: bitmap = new BitSet();
056: while (true) {
057: Tokenizer.Token t = st.get();
058: if (!t.isString())
059: break;
060: int typecode = Type.value(t.value, true);
061: if (typecode <= 0 || typecode > 128)
062: throw st.exception("Invalid type: " + t.value);
063: bitmap.set(typecode);
064: }
065: st.unget();
066: }
067:
068: /** Converts rdata to a String */
069: String rrToString() {
070: StringBuffer sb = new StringBuffer();
071: sb.append(next);
072: int length = bitmap.length();
073: for (short i = 0; i < length; i++)
074: if (bitmap.get(i)) {
075: sb.append(" ");
076: sb.append(Type.string(i));
077: }
078: return sb.toString();
079: }
080:
081: /** Returns the next name */
082: public Name getNext() {
083: return next;
084: }
085:
086: /** Returns the set of types defined for this name */
087: public BitSet getBitmap() {
088: return bitmap;
089: }
090:
091: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
092: next.toWire(out, null, canonical);
093: int length = bitmap.length();
094: for (int i = 0, t = 0; i < length; i++) {
095: t |= (bitmap.get(i) ? (1 << (7 - i % 8)) : 0);
096: if (i % 8 == 7 || i == length - 1) {
097: out.writeU8(t);
098: t = 0;
099: }
100: }
101: }
102:
103: }
|