mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Add framework for customizable WHOIS commands
With some additional changes by Ben McIlwain. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=145447136
This commit is contained in:
parent
d3fe6be385
commit
bb3a0c78c5
15 changed files with 155 additions and 47 deletions
|
@ -70,10 +70,12 @@ class WhoisReader {
|
|||
|
||||
private final Reader reader;
|
||||
private final DateTime now;
|
||||
private final WhoisCommandFactory commandFactory;
|
||||
|
||||
/** Creates a new WhoisReader that extracts its command from the specified Reader. */
|
||||
WhoisReader(Reader reader, DateTime now) {
|
||||
WhoisReader(Reader reader, WhoisCommandFactory commandFactory, DateTime now) {
|
||||
this.reader = checkNotNull(reader, "reader");
|
||||
this.commandFactory = checkNotNull(commandFactory, "commandFactory");
|
||||
this.now = checkNotNull(now, "now");
|
||||
}
|
||||
|
||||
|
@ -111,7 +113,7 @@ class WhoisReader {
|
|||
|
||||
// Try to parse the argument as a domain name.
|
||||
try {
|
||||
return new DomainLookupCommand(InternetDomainName.from(
|
||||
return commandFactory.domainLookup(InternetDomainName.from(
|
||||
canonicalizeDomainName(tokens.get(1))));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// If we can't interpret the argument as a host name, then return an error.
|
||||
|
@ -129,14 +131,14 @@ class WhoisReader {
|
|||
|
||||
// Try to parse the argument as an IP address.
|
||||
try {
|
||||
return new NameserverLookupByIpCommand(InetAddresses.forString(tokens.get(1)));
|
||||
return commandFactory.nameserverLookupByIp(InetAddresses.forString(tokens.get(1)));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// Silently ignore this exception.
|
||||
}
|
||||
|
||||
// Try to parse the argument as a host name.
|
||||
try {
|
||||
return new NameserverLookupByHostCommand(InternetDomainName.from(
|
||||
return commandFactory.nameserverLookupByHost(InternetDomainName.from(
|
||||
canonicalizeDomainName(tokens.get(1))));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// Silently ignore this exception.
|
||||
|
@ -153,14 +155,14 @@ class WhoisReader {
|
|||
throw new WhoisException(now, SC_BAD_REQUEST, String.format(
|
||||
"Too few arguments to '%s' command.", REGISTRAR_LOOKUP_COMMAND));
|
||||
}
|
||||
return new RegistrarLookupCommand(Joiner.on(' ').join(tokens.subList(1, tokens.size())));
|
||||
return commandFactory.registrarLookup(Joiner.on(' ').join(tokens.subList(1, tokens.size())));
|
||||
}
|
||||
|
||||
// If we have a single token, then try to interpret that in various ways.
|
||||
if (tokens.size() == 1) {
|
||||
// Try to parse it as an IP address. If successful, then this is a lookup on a nameserver.
|
||||
try {
|
||||
return new NameserverLookupByIpCommand(InetAddresses.forString(arg1));
|
||||
return commandFactory.nameserverLookupByIp(InetAddresses.forString(arg1));
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// Silently ignore this exception.
|
||||
}
|
||||
|
@ -180,11 +182,11 @@ class WhoisReader {
|
|||
// If the target is exactly one level above the TLD, then this is an second level domain
|
||||
// (SLD) and we should do a domain lookup on it.
|
||||
if (targetName.parent().equals(tld.get())) {
|
||||
return new DomainLookupCommand(targetName, tld.get());
|
||||
return commandFactory.domainLookup(targetName, tld.get());
|
||||
}
|
||||
|
||||
// The target is more than one level above the TLD, so we'll assume it's a nameserver.
|
||||
return new NameserverLookupByHostCommand(targetName, tld.get());
|
||||
return commandFactory.nameserverLookupByHost(targetName, tld.get());
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Silently ignore this exception.
|
||||
}
|
||||
|
@ -194,7 +196,7 @@ class WhoisReader {
|
|||
|
||||
// The only case left is that there are multiple tokens with no particular command given. We'll
|
||||
// assume this is a registrar lookup, since there's really nothing else it could be.
|
||||
return new RegistrarLookupCommand(Joiner.on(' ').join(tokens));
|
||||
return commandFactory.registrarLookup(Joiner.on(' ').join(tokens));
|
||||
}
|
||||
|
||||
/** Returns an ArrayList containing the contents of the String array minus any empty strings. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue