httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r997869 - /httpd/httpd/trunk/modules/mappers/mod_rewrite.c
Date Thu, 16 Sep 2010 18:14:32 GMT
Author: wrowe
Date: Thu Sep 16 18:14:32 2010
New Revision: 997869

URL: http://svn.apache.org/viewvc?rev=997869&view=rev
Log:
Reduce complexity and fix a regex.t based on observation by rpluem;

 - follow the same logic of '=' for >[=] and <[=], skipping p->type chars
   for the resulting p->pattern
  
 - introduce pskip logic to greatly simplify logging, track negation '!', '=', 
   and new comparators ">/<[=]", backspacing only for the purpose of logging.
   It's trivial to expand this to the -X operators in the future.


Modified:
    httpd/httpd/trunk/modules/mappers/mod_rewrite.c

Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?rev=997869&r1=997868&r2=997869&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Thu Sep 16 18:14:32 2010
@@ -273,6 +273,7 @@ typedef struct {
     ap_regex_t  *regexp;  /* the precompiled regexp        */
     int          flags;   /* Flags which control the match */
     pattern_type ptype;   /* pattern type                  */
+    int          pskip;   /* back-index to display pattern */
 } rewritecond_entry;
 
 /* single linked list for env vars and cookies */
@@ -3163,6 +3164,7 @@ static const char *cmd_rewritecond(cmd_p
     }
 
     /* arg2: the pattern */
+    newcond->pattern = a2;
     if (*a2 == '!') {
         newcond->flags |= CONDFLAG_NOTMATCH;
         ++a2;
@@ -3186,23 +3188,23 @@ static const char *cmd_rewritecond(cmd_p
         }
         else {
             switch (*a2) {
-            case '>': if (a2[1] == '=')
+            case '>': if (*++a2 == '=')
                           ++a2, newcond->ptype = CONDPAT_STR_GE;
                       else
-                          ++a2, newcond->ptype = CONDPAT_STR_GT;
+                          newcond->ptype = CONDPAT_STR_GT;
                       break;
-            case '<': newcond->ptype = CONDPAT_STR_LT;
-                      if (a2[1] == '=')
+
+            case '<': if (*++a2 == '=')
                           ++a2, newcond->ptype = CONDPAT_STR_LE;
                       else
-                          ++a2, newcond->ptype = CONDPAT_STR_LT;
+                          newcond->ptype = CONDPAT_STR_LT;
                       break;
+
             case '=': newcond->ptype = CONDPAT_STR_EQ;
-                /* "" represents an empty string */
-                if (*++a2 == '"' && a2[1] == '"' && !a2[2]) {
-                    a2 += 2;
-                }
-                break;
+                      /* "" represents an empty string */
+                      if (*++a2 == '"' && a2[1] == '"' && !a2[2])
+                          a2 += 2;
+                      break;
             }
         }
     }
@@ -3215,7 +3217,8 @@ static const char *cmd_rewritecond(cmd_p
         newcond->flags &= ~CONDFLAG_NOCASE;
     }
 
-    newcond->pattern = a2;
+    newcond->pskip = a2 - newcond->pattern;
+    newcond->pattern += newcond->pskip;
 
     if (!newcond->ptype) {
         regexp = ap_pregcomp(cmd->pool, a2,
@@ -3672,10 +3675,10 @@ static int apply_rewrite_cond(rewritecon
         basis = 1;
 test_str_g:
         if (p->flags & CONDFLAG_NOCASE) {
-            rc = (strcasecmp(input, p->pattern+1) >= basis) ? 1 : 0;
+            rc = (strcasecmp(input, p->pattern) >= basis) ? 1 : 0;
         }
         else {
-            rc = (compare_lexicography(input, p->pattern+1) >= basis) ? 1 : 0;
+            rc = (compare_lexicography(input, p->pattern) >= basis) ? 1 : 0;
         }
         break;
 
@@ -3686,10 +3689,10 @@ test_str_g:
         basis = -1;
 test_str_l:
         if (p->flags & CONDFLAG_NOCASE) {
-            rc = (strcasecmp(input, p->pattern+1) <= basis) ? 1 : 0;
+            rc = (strcasecmp(input, p->pattern) <= basis) ? 1 : 0;
         }
         else {
-            rc = (compare_lexicography(input, p->pattern+1) <= basis) ? 1 : 0;
+            rc = (compare_lexicography(input, p->pattern) <= basis) ? 1 : 0;
         }
         break;
 
@@ -3720,9 +3723,8 @@ test_str_l:
         rc = !rc;
     }
 
-    rewritelog((r, 4, ctx->perdir, "RewriteCond: input='%s' pattern='%s%s%s'%s "
-                "=> %s", input, (p->flags & CONDFLAG_NOTMATCH) ? "!" : "",
-                (p->ptype == CONDPAT_STR_EQ) ? "=" : "", p->pattern,
+    rewritelog((r, 4, ctx->perdir, "RewriteCond: input='%s' pattern='%s'%s "
+                "=> %s", input, p->pattern - p->pskip,
                 (p->flags & CONDFLAG_NOCASE) ? " [NC]" : "",
                 rc ? "matched" : "not-matched"));
 



Mime
View raw message