@ -275,51 +275,77 @@ public class Blacklist {
public final void remove ( final BlacklistType blacklistType , final String blacklistToUse , final String host , final String path ) {
public final void remove ( final BlacklistType blacklistType , final String blacklistToUse , final String host , final String path ) {
final Map < String , Set < Pattern > > blacklistMap = getBlacklistMap ( blacklistType , true ) ;
final Map < String , Set < Pattern > > blacklistMap = getBlacklistMap ( blacklistType , true ) ;
Set < Pattern > hostList = blacklistMap . get ( host ) ;
removePatternFromMap ( host , path , blacklistMap ) ;
if ( hostList ! = null ) {
// remove pattern from list (by comparing patternstring with path, remove(path) will not match path)
final Map < String , Set < Pattern > > blacklistMapNotMatch = getBlacklistMap ( blacklistType , false ) ;
for ( Pattern hp : hostList ) {
removePatternFromMap ( host , path , blacklistMapNotMatch ) ;
String hpxs = hp . pattern ( ) ;
if ( hpxs . equals ( path ) ) {
//TODO: check if delete from blacklist is desired, on reload entry will not be available in any blacklist
hostList . remove ( hp ) ;
// even if remove (above) from internal maps (at runtime) is only done for given blacklistType
// load blacklist data from file
final List < String > list = FileUtils . getListArray ( new File ( ListManager . listsPath , blacklistToUse ) ) ;
/* delete the old entry from file, in any normalized or not normalized possible combinations */
final Set < String > entriesToDelete = new HashSet < > ( ) ;
final String normalizedPathPattern = MultiProtocolURL . escapePathPattern ( path ) ;
entriesToDelete . add ( host + "/" + path ) ;
entriesToDelete . add ( host + "/" + normalizedPathPattern ) ;
if ( ! Punycode . isBasic ( host ) ) {
try {
final String normalizedHost = MultiProtocolURL . toPunycode ( host ) ;
entriesToDelete . add ( normalizedHost + "/" + path ) ;
entriesToDelete . add ( normalizedHost + "/" + normalizedPathPattern ) ;
} catch ( final PunycodeException ignored ) {
/* We continue even if a punycode flavor can not be produced */
}
}
if ( list ! = null ) {
for ( final String e : list ) {
if ( entriesToDelete . contains ( e ) ) {
list . remove ( e ) ;
break ;
break ;
}
}
}
}
if ( hostList . isEmpty ( ) ) {
FileUtils . writeList ( new File ( ListManager . listsPath , blacklistToUse ) , list . toArray ( new String [ list . size ( ) ] ) ) ;
blacklistMap . remove ( host ) ;
}
}
}
}
final Map < String , Set < Pattern > > blacklistMapNotMatch = getBlacklistMap ( blacklistType , false ) ;
/ * *
hostList = blacklistMapNotMatch . get ( host ) ;
* Remove the ( host , pathPattern ) entries eventually found in the given
* blacklist map .
*
* @param host the host part of the entry to remove
* @param pathPattern the path pattern part of the entry to remove
* @param blacklistMap a blacklist map to update
* /
private void removePatternFromMap ( final String host , final String pathPattern ,
final Map < String , Set < Pattern > > blacklistMap ) {
final String normalizedPathPattern = MultiProtocolURL . escapePathPattern ( pathPattern ) ;
final Set < String > hosts = new HashSet < > ( ) ;
hosts . add ( host ) ;
if ( ! Punycode . isBasic ( host ) ) {
try {
hosts . add ( MultiProtocolURL . toPunycode ( host ) ) ;
} catch ( final PunycodeException ignored ) {
/* We continue even if a punycode flavor can not be produced */
}
}
for ( final String hostKey : hosts ) {
final Set < Pattern > hostList = blacklistMap . get ( hostKey ) ;
if ( hostList ! = null ) {
if ( hostList ! = null ) {
// remove pattern from list
// remove pattern from list (by comparing patternstring with path, remove(path)
// will not match path)
for ( Pattern hp : hostList ) {
for ( Pattern hp : hostList ) {
String hpxs = hp . pattern ( ) ;
String hpxs = hp . pattern ( ) ;
if ( hpxs . equals ( path ) ) {
if ( hpxs . equals ( path Pattern) | | hpxs . equals ( normalizedPathPattern ) ) {
hostList . remove ( hp ) ;
hostList . remove ( hp ) ;
break ;
break ;
}
}
}
}
if ( hostList . isEmpty ( ) ) {
if ( hostList . isEmpty ( ) ) {
blacklistMapNotMatch . remove ( host ) ;
blacklistMap . remove ( host ) ;
}
}
//TODO: check if delete from blacklist is desired, on reload entry will not be available in any blacklist
// even if remove (above) from internal maps (at runtime) is only done for given blacklistType
// load blacklist data from file
final List < String > list = FileUtils . getListArray ( new File ( ListManager . listsPath , blacklistToUse ) ) ;
// delete the old entry from file
if ( list ! = null ) {
for ( final String e : list ) {
if ( e . equals ( host + "/" + path ) ) {
list . remove ( e ) ;
break ;
}
}
}
}
FileUtils . writeList ( new File ( ListManager . listsPath , blacklistToUse ) , list . toArray ( new String [ list . size ( ) ] ) ) ;
}
}
}
}