tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11 Http11Processor.java
Date Wed, 01 Sep 2004 10:10:11 GMT
remm        2004/09/01 03:10:11

  Modified:    catalina/src/share/org/apache/catalina/valves
                        RequestFilterValve.java
               http11/src/java/org/apache/coyote/http11
                        Http11Processor.java
  Log:
  - Use the JDK 1.4 regexp API, which is a straight replacement for jakarta-regexp. It's easy
to switch back and forth, obviously, which is
    quite convinient :)
  
  Revision  Changes    Path
  1.9       +14 -14    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/RequestFilterValve.java
  
  Index: RequestFilterValve.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/RequestFilterValve.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- RequestFilterValve.java	29 Aug 2004 16:46:14 -0000	1.8
  +++ RequestFilterValve.java	1 Sep 2004 10:10:10 -0000	1.9
  @@ -20,6 +20,8 @@
   
   import java.io.IOException;
   import java.util.ArrayList;
  +import java.util.regex.Pattern;
  +import java.util.regex.PatternSyntaxException;
   
   import javax.servlet.ServletException;
   import javax.servlet.http.HttpServletResponse;
  @@ -27,8 +29,6 @@
   import org.apache.catalina.connector.Request;
   import org.apache.catalina.connector.Response;
   import org.apache.catalina.util.StringManager;
  -import org.apache.regexp.RE;
  -import org.apache.regexp.RESyntaxException;
   import org.apache.tomcat.util.compat.JdkCompat;
   
   /**
  @@ -104,13 +104,13 @@
       /**
        * The set of <code>allow</code> regular expressions we will evaluate.
        */
  -    protected RE allows[] = new RE[0];
  +    protected Pattern allows[] = new Pattern[0];
   
   
       /**
        * The set of <code>deny</code> regular expressions we will evaluate.
        */
  -    protected RE denies[] = new RE[0];
  +    protected Pattern denies[] = new Pattern[0];
   
   
       /**
  @@ -214,13 +214,13 @@
        * @exception IllegalArgumentException if one of the patterns has
        *  invalid syntax
        */
  -    protected RE[] precalculate(String list) {
  +    protected Pattern[] precalculate(String list) {
   
           if (list == null)
  -            return (new RE[0]);
  +            return (new Pattern[0]);
           list = list.trim();
           if (list.length() < 1)
  -            return (new RE[0]);
  +            return (new Pattern[0]);
           list += ",";
   
           ArrayList reList = new ArrayList();
  @@ -230,8 +230,8 @@
                   break;
               String pattern = list.substring(0, comma).trim();
               try {
  -                reList.add(new RE(pattern));
  -            } catch (RESyntaxException e) {
  +                reList.add(Pattern.compile(pattern));
  +            } catch (PatternSyntaxException e) {
                   IllegalArgumentException iae = new IllegalArgumentException
                       (sm.getString("requestFilterValve.syntax", pattern));
                   jdkCompat.chainException(iae, e);
  @@ -240,8 +240,8 @@
               list = list.substring(comma + 1);
           }
   
  -        RE reArray[] = new RE[reList.size()];
  -        return ((RE[]) reList.toArray(reArray));
  +        Pattern reArray[] = new Pattern[reList.size()];
  +        return ((Pattern[]) reList.toArray(reArray));
   
       }
   
  @@ -263,7 +263,7 @@
   
           // Check the deny patterns, if any
           for (int i = 0; i < denies.length; i++) {
  -            if (denies[i].match(property)) {
  +            if (denies[i].matcher(property).matches()) {
                   response.sendError(HttpServletResponse.SC_FORBIDDEN);
                   return;
               }
  @@ -271,7 +271,7 @@
   
           // Check the allow patterns, if any
           for (int i = 0; i < allows.length; i++) {
  -            if (allows[i].match(property)) {
  +            if (allows[i].matcher(property).matches()) {
                   getNext().invoke(request, response);
                   return;
               }
  
  
  
  1.107     +18 -18    jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java
  
  Index: Http11Processor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11Processor.java,v
  retrieving revision 1.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- Http11Processor.java	31 Aug 2004 23:52:51 -0000	1.106
  +++ Http11Processor.java	1 Sep 2004 10:10:11 -0000	1.107
  @@ -23,6 +23,8 @@
   import java.net.InetAddress;
   import java.net.Socket;
   import java.util.StringTokenizer;
  +import java.util.regex.Pattern;
  +import java.util.regex.PatternSyntaxException;
   import java.security.AccessController;
   import java.security.PrivilegedAction;
   
  @@ -41,8 +43,6 @@
   import org.apache.coyote.http11.filters.VoidInputFilter;
   import org.apache.coyote.http11.filters.VoidOutputFilter;
   import org.apache.coyote.http11.filters.BufferedInputFilter;
  -import org.apache.regexp.RE;
  -import org.apache.regexp.RESyntaxException;
   import org.apache.tomcat.util.buf.Ascii;
   import org.apache.tomcat.util.buf.ByteChunk;
   import org.apache.tomcat.util.buf.HexUtils;
  @@ -179,7 +179,7 @@
       /**
        * List of restricted user agents.
        */
  -    protected RE[] restrictedUserAgents = null;
  +    protected Pattern[] restrictedUserAgents = null;
   
   
       /**
  @@ -276,7 +276,7 @@
       /**
        * List of user agents to not use gzip with
        */
  -    protected RE noCompressionUserAgents[] = null;
  +    protected Pattern noCompressionUserAgents[] = null;
       
       /**
        * List of MIMES which could be gzipped
  @@ -359,11 +359,11 @@
        */
       public void addNoCompressionUserAgent(String userAgent) {
           try {
  -            RE nRule = new RE(userAgent);
  +            Pattern nRule = Pattern.compile(userAgent);
               noCompressionUserAgents = 
                   addREArray(noCompressionUserAgents, nRule);
  -        } catch (RESyntaxException ree) {
  -            log.error("Error parsing regular expression: " + userAgent, ree);
  +        } catch (PatternSyntaxException pse) {
  +            log.error("Error parsing regular expression: " + userAgent, pse);
           }
       }
   
  @@ -373,7 +373,7 @@
        * a large number of connectors, where it would be better to have all of 
        * them referenced a single array).
        */
  -    public void setNoCompressionUserAgents(RE[] noCompressionUserAgents) {
  +    public void setNoCompressionUserAgents(Pattern[] noCompressionUserAgents) {
           this.noCompressionUserAgents = noCompressionUserAgents;
       }
   
  @@ -496,14 +496,14 @@
        * @param rArray the REArray 
        * @param value Obj
        */
  -    private RE[] addREArray(RE rArray[], RE value) {
  -        RE[] result = null;
  +    private Pattern[] addREArray(Pattern rArray[], Pattern value) {
  +        Pattern[] result = null;
           if (rArray == null) {
  -            result = new RE[1];
  +            result = new Pattern[1];
               result[0] = value;
           }
           else {    
  -            result = new RE[rArray.length + 1];
  +            result = new Pattern[rArray.length + 1];
               for (int i = 0; i < rArray.length; i++)
                   result[i] = rArray[i];
               result[rArray.length] = value;
  @@ -555,10 +555,10 @@
        */
       public void addRestrictedUserAgent(String userAgent) {
           try {
  -            RE nRule = new RE(userAgent);
  +            Pattern nRule = Pattern.compile(userAgent);
               restrictedUserAgents = addREArray(restrictedUserAgents, nRule);
  -        } catch (RESyntaxException ree) {
  -            log.error("Error parsing regular expression: " + userAgent, ree);
  +        } catch (PatternSyntaxException pse) {
  +            log.error("Error parsing regular expression: " + userAgent, pse);
           }
       }
   
  @@ -568,7 +568,7 @@
        * a large number of connectors, where it would be better to have all of 
        * them referenced a single array).
        */
  -    public void setRestrictedUserAgents(RE[] restrictedUserAgents) {
  +    public void setRestrictedUserAgents(Pattern[] restrictedUserAgents) {
           this.restrictedUserAgents = restrictedUserAgents;
       }
   
  @@ -1157,7 +1157,7 @@
               if(userAgentValueMB != null) {
                   String userAgentValue = userAgentValueMB.toString();
                   for (int i = 0; i < restrictedUserAgents.length; i++) {
  -                    if (restrictedUserAgents[i].match(userAgentValue)) {
  +                    if (restrictedUserAgents[i].matcher(userAgentValue).matches()) {
                           http11 = false;
                           keepAlive = false;
                           break;
  @@ -1383,7 +1383,7 @@
   
                   // If one Regexp rule match, disable compression
                   for (int i = 0; i < noCompressionUserAgents.length; i++)
  -                    if (noCompressionUserAgents[i].match(userAgentValue))
  +                    if (noCompressionUserAgents[i].matcher(userAgentValue).matches())
                           return false;
               }
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message