1 18 package net.sf.drftpd; 19 20 import java.net.InetAddress ; 21 22 import org.apache.log4j.Logger; 23 import org.apache.oro.text.GlobCompiler; 24 import org.apache.oro.text.regex.MalformedPatternException; 25 import org.apache.oro.text.regex.Pattern; 26 import org.apache.oro.text.regex.Perl5Matcher; 27 28 32 public class HostMask { 33 private static final Logger logger = Logger.getLogger(HostMask.class); 34 private String _hostMask; 35 private String _identMask; 36 37 public HostMask(String string) { 38 int pos = string.indexOf('@'); 39 if (pos == -1) { 40 _identMask = null; 41 _hostMask = string; 42 } else { 43 _identMask = string.substring(0, pos); 44 _hostMask = string.substring(pos + 1); 45 } 46 } 47 48 public String getHostMask() { 49 return _hostMask; 50 } 51 52 public String getIdentMask() { 53 return _identMask; 54 } 55 56 60 public boolean isIdentMaskSignificant() { 61 return _identMask != null && !_identMask.equals("*"); 62 } 63 64 public boolean matches(String ident, InetAddress address) { 65 if(ident == null) ident = ""; 66 Perl5Matcher m = new Perl5Matcher(); 67 68 GlobCompiler c = new GlobCompiler(); 69 try { 70 if (!isIdentMaskSignificant() 71 || m.matches(ident, c.compile(getIdentMask()))) { 72 Pattern p = c.compile(getHostMask()); 73 if (m.matches(address.getHostAddress(), p) 74 || m.matches(address.getHostName(), p)) { 75 return true; 76 } 77 } 78 return false; 79 } catch (MalformedPatternException ex) { 80 logger.warn("", ex); 81 return false; 82 } 83 } 84 } 85 | Popular Tags |