/**
   * Builds a new Record from its textual representation
   *
   * @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 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, int dclass, long ttl, Tokenizer st, Name origin) throws IOException {
    Record rec;

    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    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, dclass, ttl, length, in);
    }
    st.unget();
    rec = getEmptyRecord(name, type, dclass, 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;
  }
Beispiel #2
0
  /**
   * Creates a specification for generating records, as a $GENERATE statement in a master file.
   *
   * @param start The start of the range.
   * @param end The end of the range.
   * @param step The step value of the range.
   * @param namePattern The pattern to use for generating record names.
   * @param type The type of the generated records. The supported types are PTR, CNAME, DNAME, A,
   *     AAAA, and NS.
   * @param dclass The class of the generated records.
   * @param ttl The ttl of the generated records.
   * @param rdataPattern The pattern to use for generating record data.
   * @param origin The origin to append to relative names.
   * @throws IllegalArgumentException The range is invalid.
   * @throws IllegalArgumentException The type does not support generation.
   * @throws IllegalArgumentException The dclass is not a valid class.
   */
  public Generator(
      long start,
      long end,
      long step,
      String namePattern,
      int type,
      int dclass,
      long ttl,
      String rdataPattern,
      Name origin) {
    if (start < 0 || end < 0 || start > end || step <= 0)
      throw new IllegalArgumentException("invalid range specification");
    if (!supportedType(type)) throw new IllegalArgumentException("unsupported type");
    DClass.check(dclass);

    this.start = start;
    this.end = end;
    this.step = step;
    this.namePattern = namePattern;
    this.type = type;
    this.dclass = dclass;
    this.ttl = ttl;
    this.rdataPattern = rdataPattern;
    this.origin = origin;
    this.current = start;
  }
  /**
   * 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, int dclass, long ttl) {
    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    TTL.check(ttl);

    return getEmptyRecord(name, type, dclass, ttl, false);
  }
 Record(Name name, int type, int dclass, long ttl) {
   if (!name.isAbsolute()) throw new RelativeNameException(name);
   Type.check(type);
   DClass.check(dclass);
   TTL.check(ttl);
   this.name = name;
   this.type = type;
   this.dclass = dclass;
   this.ttl = ttl;
 }
  /**
   * 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, int dclass, long ttl, int length, byte[] data) {
    if (!name.isAbsolute()) throw new RelativeNameException(name);
    Type.check(type);
    DClass.check(dclass);
    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;
    }
  }