Ejemplo n.º 1
0
  /**
   * Looks up Records in the Zone. This follows CNAMEs and wildcards.
   *
   * @param name The name to look up
   * @param type The type to look up
   * @return A SetResponse object
   * @see SetResponse
   */
  public SetResponse findRecords(Name name, short type) {
    SetResponse zr = null;

    Object o = findSets(name, type);
    if (o == null) {
      /* The name does not exist */
      if (name.isWild()) return SetResponse.ofType(SetResponse.NXDOMAIN);

      int labels = name.labels() - origin.labels();
      if (labels == 0) return SetResponse.ofType(SetResponse.NXDOMAIN);
      if (hasWild) {
        SetResponse sr;
        Name tname = name;
        do {
          sr = findRecords(tname.wild(1), type);
          if (!sr.isNXDOMAIN()) return sr;
          tname = new Name(tname, 1);
        } while (labels-- >= 1);
        return sr;
      } else return SetResponse.ofType(SetResponse.NXDOMAIN);
    }

    if (o instanceof TypeMap) {
      /* The name exists but the type does not. */
      return SetResponse.ofType(SetResponse.NXRRSET);
    }

    Object[] objects;
    RRset rrset;

    if (o instanceof RRset) {
      objects = null;
      rrset = (RRset) o;
    } else {
      objects = (Object[]) o;
      rrset = (RRset) objects[0];
    }

    if (name.equals(rrset.getName())) {
      if (type != Type.CNAME && type != Type.ANY && rrset.getType() == Type.CNAME)
        zr = new SetResponse(SetResponse.CNAME, rrset);
      else if (rrset.getType() == Type.NS && !name.equals(origin))
        zr = new SetResponse(SetResponse.DELEGATION, rrset);
      else {
        zr = new SetResponse(SetResponse.SUCCESSFUL);
        zr.addRRset(rrset);
        if (objects != null) {
          for (int i = 1; i < objects.length; i++) zr.addRRset((RRset) objects[i]);
        }
      }
    } else {
      if (rrset.getType() == Type.CNAME) return SetResponse.ofType(SetResponse.NXDOMAIN);
      else if (rrset.getType() == Type.DNAME) {
        zr = new SetResponse(SetResponse.DNAME, rrset);
      } else if (rrset.getType() == Type.NS) {
        zr = new SetResponse(SetResponse.DELEGATION, rrset);
      }
    }
    return zr;
  }
Ejemplo n.º 2
0
 private synchronized void addRRset(Name name, RRset rrset) {
   if (!hasWild && name.isWild()) hasWild = true;
   Object types = data.get(name);
   if (types == null) {
     data.put(name, rrset);
     return;
   }
   int rtype = rrset.getType();
   if (types instanceof List) {
     List list = (List) types;
     for (int i = 0; i < list.size(); i++) {
       RRset set = (RRset) list.get(i);
       if (set.getType() == rtype) {
         list.set(i, rrset);
         return;
       }
     }
     list.add(rrset);
   } else {
     RRset set = (RRset) types;
     if (set.getType() == rtype) data.put(name, rrset);
     else {
       LinkedList list = new LinkedList();
       list.add(set);
       list.add(rrset);
       data.put(name, list);
     }
   }
 }
Ejemplo n.º 3
0
 /** Adds a set associated with a name/type. The data contained in the set is abstract. */
 protected void addSet(Name name, short type, TypedObject set) {
   if (!hasWild && name.isWild()) hasWild = true;
   super.addSet(name, type, set);
 }