예제 #1
0
파일: dns.java 프로젝트: lemmy/dnsjava
 /**
  * Finds records with the given name, type, and class with a certain credibility
  *
  * @param namestr The name of the desired records
  * @param type The type of the desired records
  * @param dclass The class of the desired records
  * @param cred The minimum credibility of the desired records
  * @see Credibility
  * @return The matching records, or null if none are found
  */
 public static Record[] getRecords(String namestr, int type, int dclass, byte cred) {
   try {
     Lookup lookup = new Lookup(namestr, type, dclass);
     lookup.setCredibility(cred);
     return lookup.run();
   } catch (Exception e) {
     return null;
   }
 }
 private static void addCurrentlySelectedItemToTop(
     Lookup lookup, List<LookupElement> items, LinkedHashSet<LookupElement> model) {
   if (!lookup.isSelectionTouched()) {
     LookupElement lastSelection = lookup.getCurrentItem();
     if (ContainerUtil.indexOfIdentity(items, lastSelection) >= 0) {
       model.add(lastSelection);
     }
   }
 }
예제 #3
0
파일: dns.java 프로젝트: lemmy/dnsjava
  /**
   * Specifies the domains which will be appended to unqualified names before beginning the lookup
   * process. If this is not set, FindServer will be used. Unlike the Lookup setSearchPath function,
   * this will silently ignore invalid names.
   *
   * @see FindServer
   */
  public static synchronized void setSearchPath(String[] domains) {
    if (domains == null || domains.length == 0) {
      Lookup.setDefaultSearchPath((Name[]) null);
      return;
    }

    List l = new ArrayList();
    for (int i = 0; i < domains.length; i++) {
      try {
        l.add(Name.fromString(domains[i], Name.root));
      } catch (TextParseException e) {
      }
    }
    searchPath = (Name[]) l.toArray(new Name[l.size()]);
    Lookup.setDefaultSearchPath(searchPath);
  }
  public static StatisticsUpdate collectStatisticChanges(LookupElement item, final Lookup lookup) {
    applyLastCompletionStatisticsUpdate();

    final StatisticsInfo base = StatisticsWeigher.getBaseStatisticsInfo(item, null);
    if (base == StatisticsInfo.EMPTY) {
      return new StatisticsUpdate(StatisticsInfo.EMPTY);
    }

    StatisticsUpdate update =
        new StatisticsUpdate(
            StatisticsWeigher.composeStatsWithPrefix(base, lookup.itemPattern(item), true));
    ourPendingUpdate = update;
    Disposer.register(
        update,
        new Disposable() {
          @Override
          public void dispose() {
            //noinspection AssignmentToStaticFieldFromInstanceMethod
            ourPendingUpdate = null;
          }
        });

    return update;
  }
예제 #5
0
  public static void main(String[] args) throws Exception {
    ZoneTransferIn xfrin;
    TSIG key = null;
    int ixfr_serial = -1;
    String server = null;
    int port = SimpleResolver.DEFAULT_PORT;
    boolean fallback = false;
    Name zname;

    int arg = 0;
    while (arg < args.length) {
      if (args[arg].equals("-i")) {
        ixfr_serial = Integer.parseInt(args[++arg]);
        if (ixfr_serial < 0) usage("invalid serial number");
      } else if (args[arg].equals("-k")) {
        String s = args[++arg];
        int index = s.indexOf('/');
        if (index < 0) usage("invalid key");
        key = new TSIG(s.substring(0, index), s.substring(index + 1));
      } else if (args[arg].equals("-s")) {
        server = args[++arg];
      } else if (args[arg].equals("-p")) {
        port = Integer.parseInt(args[++arg]);
        if (port < 0 || port > 0xFFFF) usage("invalid port");
      } else if (args[arg].equals("-f")) {
        fallback = true;
      } else if (args[arg].startsWith("-")) {
        usage("invalid option");
      } else {
        break;
      }
      arg++;
    }
    if (arg >= args.length) usage("no zone name specified");
    zname = Name.fromString(args[arg]);

    if (server == null) {
      Lookup l = new Lookup(zname, Type.NS);
      Record[] ns = l.run();
      if (ns == null) {
        System.out.println("failed to look up NS record: " + l.getErrorString());
        System.exit(1);
      }
      server = ns[0].rdataToString();
      System.out.println("sending to server '" + server + "'");
    }

    if (ixfr_serial >= 0)
      xfrin = ZoneTransferIn.newIXFR(zname, ixfr_serial, fallback, server, port, key);
    else xfrin = ZoneTransferIn.newAXFR(zname, server, port, key);

    List response = xfrin.run();
    if (xfrin.isAXFR()) {
      if (ixfr_serial >= 0) System.out.println("AXFR-like IXFR response");
      else System.out.println("AXFR response");
      Iterator it = response.iterator();
      while (it.hasNext()) System.out.println(it.next());
    } else if (xfrin.isIXFR()) {
      System.out.println("IXFR response");
      Iterator it = response.iterator();
      while (it.hasNext()) {
        ZoneTransferIn.Delta delta;
        delta = (ZoneTransferIn.Delta) it.next();
        System.out.println("delta from " + delta.start + " to " + delta.end);
        System.out.println("deletes");
        Iterator it2 = delta.deletes.iterator();
        while (it2.hasNext()) System.out.println(it2.next());
        System.out.println("adds");
        it2 = delta.adds.iterator();
        while (it2.hasNext()) System.out.println(it2.next());
      }
    } else if (xfrin.isCurrent()) {
      System.out.println("up to date");
    }
  }
예제 #6
0
파일: dns.java 프로젝트: lemmy/dnsjava
 /**
  * Obtains the Cache used by functions in the dns class. This can be used to perform more specific
  * queries and/or remove elements.
  *
  * @param dclass The dns class of data in the cache
  */
 public static synchronized Cache getCache(int dclass) {
   return Lookup.getDefaultCache(dclass);
 }
예제 #7
0
파일: dns.java 프로젝트: lemmy/dnsjava
 /**
  * Obtains the Resolver used by functions in the dns class. This can be used to set Resolver
  * properties.
  */
 public static synchronized Resolver getResolver() {
   return Lookup.getDefaultResolver();
 }
예제 #8
0
파일: dns.java 프로젝트: lemmy/dnsjava
 /** Sets the Resolver to be used by functions in the dns class */
 public static synchronized void setResolver(Resolver res) {
   Lookup.setDefaultResolver(res);
 }
예제 #9
0
파일: dns.java 프로젝트: lemmy/dnsjava
 /**
  * Obtains the (class IN) Cache used by functions in the dns class. This can be used to perform
  * more specific queries and/or remove elements.
  */
 public static synchronized Cache getCache() {
   return Lookup.getDefaultCache(DClass.IN);
 }