示例#1
0
  /**
   * Builds a new Record from its textual representation
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param defaultClass The record's class.
   * @param ttl The record's time to live.
   * @param st A tokenizer containing the textual representation of the rdata.
   * @param origin The default origin to be appended to relative domain names.
   * @return The new record
   * @throws IOException The text format was invalid.
   */
  public static Record fromString(
      Name name, int type, DClass defaultClass, long ttl, Tokenizer st, Name origin)
      throws IOException {
    Record rec;

    if (!name.isAbsolute()) {
      throw new RelativeNameException(name);
    }
    Type.check(type);
    TTL.check(ttl);

    Tokenizer.Token t = st.get();
    if (t.type == Tokenizer.IDENTIFIER && t.value.equals("\\#")) {
      int length = st.getUInt16();
      byte[] data = st.getHex();
      if (data == null) {
        data = new byte[0];
      }
      if (length != data.length)
        throw st.exception("invalid unknown RR encoding: " + "length mismatch");
      DNSInput in = new DNSInput(data);
      return newRecord(name, type, defaultClass, ttl, length, in);
    }
    st.unget();
    rec = getEmptyRecord(name, type, defaultClass, ttl, true);
    rec.rdataFromString(st, origin);
    t = st.get();
    if (t.type != Tokenizer.EOL && t.type != Tokenizer.EOF) {
      throw st.exception("unexpected tokens at end of record");
    }
    return rec;
  }
示例#2
0
 /** Converts a Record into a String representation */
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(name);
   if (sb.length() < 8) {
     sb.append("\t");
   }
   if (sb.length() < 16) {
     sb.append("\t");
   }
   sb.append("\t");
   if (Options.check("BINDTTL")) {
     sb.append(TTL.format(ttl));
   } else {
     sb.append(ttl);
   }
   sb.append("\t");
   if (dclass != DClass.IN || !Options.check("noPrintIN")) {
     sb.append(dclass.getName());
     sb.append("\t");
   }
   sb.append(Type.string(type));
   String rdata = rrToString();
   if (!rdata.equals("")) {
     sb.append("\t");
     sb.append(rdata);
   }
   return sb.toString();
 }
示例#3
0
 /**
  * Gets the next token from a tokenizer and parses it as if it were a TTL.
  *
  * @return The next token in the stream, as an unsigned 32 bit integer.
  * @throws TextParseException The input was not valid.
  * @throws IOException An I/O error occurred.
  * @see TTL
  */
 public long getTTLLike() throws IOException {
   String next = _getIdentifier("a TTL-like value");
   try {
     return TTL.parse(next, false);
   } catch (NumberFormatException e) {
     throw exception("expected a TTL-like value");
   }
 }
示例#4
0
  /**
   * Creates a new empty record, with the given parameters.
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param dclass The record's class.
   * @param ttl The record's time to live.
   * @return An object of a subclass of Record
   */
  public static Record newRecord(Name name, int type, DClass dclass, long ttl) {
    if (!name.isAbsolute()) {
      throw new RelativeNameException(name);
    }
    Type.check(type);
    TTL.check(ttl);

    return getEmptyRecord(name, type, dclass, ttl, false);
  }
示例#5
0
 protected Record(Name name, int type, DClass dclass, long ttl) {
   if (!name.isAbsolute()) {
     throw new RelativeNameException(name);
   }
   Type.check(type);
   TTL.check(ttl);
   this.name = name;
   this.type = type;
   this.dclass = dclass;
   this.ttl = ttl;
 }
示例#6
0
  /**
   * Creates a new record, with the given parameters.
   *
   * @param name The owner name of the record.
   * @param type The record's type.
   * @param dclass The record's class.
   * @param ttl The record's time to live.
   * @param length The length of the record's data.
   * @param data The rdata of the record, in uncompressed DNS wire format. Only the first length
   *     bytes are used.
   */
  public static Record newRecord(
      Name name, int type, DClass dclass, long ttl, int length, byte[] data) {

    if (!name.isAbsolute()) {
      throw new RelativeNameException(name);
    }
    Type.check(type);
    TTL.check(ttl);

    DNSInput in;
    if (data != null) {
      in = new DNSInput(data);
    } else {
      in = null;
    }
    try {
      return newRecord(name, type, dclass, ttl, length, in);
    } catch (IOException e) {
      return null;
    }
  }