示例#1
0
 /** Converts the NameSet to a String */
 public String toString() {
   StringBuffer sb = new StringBuffer();
   Iterator it = data.values().iterator();
   while (it.hasNext()) {
     TypeMap nameInfo = (TypeMap) it.next();
     Object[] elements = nameInfo.getAll();
     if (elements == null) continue;
     for (int i = 0; i < elements.length; i++) {
       sb.append(elements[i]);
       sb.append("\n");
     }
   }
   return sb.toString();
 }
示例#2
0
  /** Finds all matching sets or something that causes the lookup to stop. */
  protected Object findSets(Name name, short type) {
    Object bestns = null;
    Object o;
    Name tname;
    int labels;
    int olabels;
    int tlabels;

    if (!name.subdomain(origin)) return null;
    labels = name.labels();
    olabels = origin.labels();

    for (tlabels = olabels; tlabels <= labels; tlabels++) {
      if (tlabels == olabels) tname = origin;
      else if (tlabels == labels) tname = name;
      else tname = new Name(name, labels - tlabels);
      TypeMap nameInfo = findName(tname);
      if (nameInfo == null) continue;

      /* If this is an ANY lookup, return everything. */
      if (tlabels == labels && type == Type.ANY) return nameInfo.getAll();

      /* Look for an NS */
      if (tlabels > olabels || isCache) {
        o = nameInfo.get(Type.NS);
        if (o != null) {
          if (isCache) bestns = o;
          else return o;
        }
      }

      /* If this is the name, look for the actual type. */
      if (tlabels == labels) {
        o = nameInfo.get(type);
        if (o != null) return o;
      }

      /* If this is the name, look for a CNAME */
      if (tlabels == labels) {
        o = nameInfo.get(Type.CNAME);
        if (o != null) return o;
      }

      /* Look for a DNAME, unless this is the actual name */
      if (tlabels < labels) {
        o = nameInfo.get(Type.DNAME);
        if (o != null) return o;
      }

      /*
       * If this is the name and this is a cache, look for an
       * NXDOMAIN entry.
       */
      if (tlabels == labels && isCache) {
        o = nameInfo.get((short) 0);
        if (o != null) return o;
      }

      /*
       * If this is the name and we haven't matched anything,
       * just return the name.
       */
      if (tlabels == labels) return nameInfo;
    }
    if (bestns == null) return null;
    else return bestns;
  }