Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
*) added new method "contains()" to Blacklist interface *) implemented contains() in class AbstractBlacklist *) used new method in Blacklist_p to prevent double entries in blacklists
low012d1116c049f8f
diff --git a/htroot/Blacklist_p.java b/htroot/Blacklist_p.javaindex b94299776..b03ef42a7 100644--- a/htroot/Blacklist_p.java+++ b/htroot/Blacklist_p.java@@ -249,7 +249,7 @@ public class Blacklist_p {* =========================================================== */blacklistToUse = post.get("currentBlacklist");-+final String temp = addBlacklistEntry(post.get("currentBlacklist"),post.get("newEntry"), header, supportedBlacklistTypes);if (temp != null) {@@ -518,6 +518,8 @@ public class Blacklist_p {if (newEntry.startsWith("http://") ){newEntry = newEntry.substring(7);+ } else if (newEntry.startsWith("https://")) {+ newEntry = newEntry.substring(8);}int pos = newEntry.indexOf("/");@@ -527,22 +529,32 @@ public class Blacklist_p {newEntry = newEntry + "/.*";}- // append the line to the file- PrintWriter pw = null;- try {- pw = new PrintWriter(new FileWriter(new File(listManager.listsPath, blacklistToUse), true));- pw.println(newEntry);- pw.close();- } catch (final IOException e) {- e.printStackTrace();- } finally {- if (pw != null) try { pw.close(); } catch (final Exception e){ Log.logWarning("Blacklist", "could not close stream to "+ blacklistToUse +"! "+ e.getMessage());}- }+ if (supportedBlacklistTypes.length > 0 &&+ !plasmaSwitchboard.urlBlacklist.contains(supportedBlacklistTypes[0], newEntry.substring(0, pos), newEntry.substring(pos + 1))) {+ // append the line to the file+ PrintWriter pw = null;+ try {+ pw = new PrintWriter(new FileWriter(new File(listManager.listsPath, blacklistToUse), true));+ pw.println(newEntry);+ pw.close();+ } catch (final IOException e) {+ e.printStackTrace();+ } finally {+ if (pw != null) {+ try {+ pw.close();+ } catch (final Exception e) {+ Log.logWarning("Blacklist", "could not close stream to " + blacklistToUse + "! " + e.getMessage());+ }- // add to blacklist- for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) {- if (listManager.listSetContains(supportedBlacklistTypes[blTypes] + ".BlackLists",blacklistToUse)) {- plasmaSwitchboard.urlBlacklist.add(supportedBlacklistTypes[blTypes],newEntry.substring(0, pos), newEntry.substring(pos + 1));+ }+ }++ // add to blacklist+ for (int blTypes = 0; blTypes < supportedBlacklistTypes.length; blTypes++) {+ if (listManager.listSetContains(supportedBlacklistTypes[blTypes] + ".BlackLists", blacklistToUse)) {+ plasmaSwitchboard.urlBlacklist.add(supportedBlacklistTypes[blTypes], newEntry.substring(0, pos), newEntry.substring(pos + 1));+ }}}diff --git a/source/de/anomic/data/AbstractBlacklist.java b/source/de/anomic/data/AbstractBlacklist.javaindex 519eb25db..45284713a 100644--- a/source/de/anomic/data/AbstractBlacklist.java+++ b/source/de/anomic/data/AbstractBlacklist.java@@ -244,6 +244,23 @@ public abstract class AbstractBlacklist implements Blacklist {return urlHashCache.contains(urlHash);}+ public boolean contains(final String blacklistType, String host, String path) {+ boolean ret = false;++ if (blacklistType != null && host != null && path != null) {+ HashMap<String, ArrayList<String>> blacklistMap;+ blacklistMap = (isMatchable(host)) ? getBlacklistMap(blacklistType,true) : getBlacklistMap(blacklistType,false);++ // avoid PatternSyntaxException e+ if(!isMatchable(host) && host.startsWith("*"))+ host = "." + host;++ ArrayList<String> hostList = blacklistMap.get(host.toLowerCase());+ if (hostList != null) ret = hostList.contains(path);+ }+ return ret;+ }+public boolean isListed(final String blacklistType, final yacyURL url) {final Set<String> urlHashCache = getCacheUrlHashsSet(blacklistType);diff --git a/source/de/anomic/data/Blacklist.java b/source/de/anomic/data/Blacklist.javaindex fb286b5f1..f85e6f87d 100644--- a/source/de/anomic/data/Blacklist.java+++ b/source/de/anomic/data/Blacklist.java@@ -87,10 +87,12 @@ public interface Blacklist {public void loadList(blacklistFile[] blFiles, String sep);+ public boolean contains(String blacklistType, String host, String path);+public boolean hashInBlacklistedCache(String blacklistType, String urlHash);public boolean isListed(String blacklistType, yacyURL url);- public boolean isListed(String blacklistType, String hostlow, String path);+ public boolean isListed(String blacklistType, String hostlow, String path);}