forked from I2P_Developers/i2p.i2p
NamingServices: Add support for lookups prefixed with "www."
This commit is contained in:
@@ -621,11 +621,33 @@ public class BlockfileNamingService extends DummyNamingService {
|
||||
////////// Start NamingService API
|
||||
|
||||
/*
|
||||
*
|
||||
* Will strip a "www." prefix and retry if lookup fails
|
||||
*
|
||||
* @param hostname upper/lower case ok
|
||||
* @param options If non-null and contains the key "list", lookup in
|
||||
* that list only, otherwise all lists
|
||||
*/
|
||||
@Override
|
||||
public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
|
||||
Destination rv = lookup2(hostname, lookupOptions, storedOptions);
|
||||
if (rv == null) {
|
||||
// if hostname starts with "www.", strip and try again
|
||||
// but not for www.i2p
|
||||
hostname = hostname.toLowerCase(Locale.US);
|
||||
if (hostname.startsWith("www.") && hostname.length() > 7) {
|
||||
hostname = hostname.substring(4);
|
||||
rv = lookup2(hostname, lookupOptions, storedOptions);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* @param options If non-null and contains the key "list", lookup in
|
||||
* that list only, otherwise all lists
|
||||
*/
|
||||
private Destination lookup2(String hostname, Properties lookupOptions, Properties storedOptions) {
|
||||
String listname = null;
|
||||
if (lookupOptions != null)
|
||||
listname = lookupOptions.getProperty("list");
|
||||
|
||||
@@ -77,6 +77,8 @@ public class SingleFileNamingService extends NamingService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Will strip a "www." prefix and retry if lookup fails
|
||||
*
|
||||
* @param hostname case-sensitive; caller should convert to lower case
|
||||
* @param lookupOptions ignored
|
||||
* @param storedOptions ignored
|
||||
@@ -85,6 +87,8 @@ public class SingleFileNamingService extends NamingService {
|
||||
public Destination lookup(String hostname, Properties lookupOptions, Properties storedOptions) {
|
||||
try {
|
||||
String key = getKey(hostname);
|
||||
if (key == null && hostname.startsWith("www.") && hostname.length() > 7)
|
||||
key = getKey(hostname.substring(4));
|
||||
if (key != null)
|
||||
return lookupBase64(key);
|
||||
} catch (Exception ioe) {
|
||||
|
||||
Reference in New Issue
Block a user