httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r1002415 - in /httpd/httpd/trunk: include/ap_expr.h server/util_expr.c
Date Tue, 28 Sep 2010 23:26:45 GMT
Author: niq
Date: Tue Sep 28 23:26:44 2010
New Revision: 1002415

URL: http://svn.apache.org/viewvc?rev=1002415&view=rev
Log:
Add "IN" operator to expression parser, to evaluate membership of
a list of tokens.  Couldn't resist after sf's comment on r1002363!

This means expressions like
<If %{REQUEST_METHOD} IN GET,HEAD,OPTIONS,...>
will work as a drop-in substitute for <Limit>

Also fix off-by-one bug in variable evaluation

Modified:
    httpd/httpd/trunk/include/ap_expr.h
    httpd/httpd/trunk/server/util_expr.c

Modified: httpd/httpd/trunk/include/ap_expr.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/include/ap_expr.h?rev=1002415&r1=1002414&r2=1002415&view=diff
==============================================================================
--- httpd/httpd/trunk/include/ap_expr.h (original)
+++ httpd/httpd/trunk/include/ap_expr.h Tue Sep 28 23:26:44 2010
@@ -45,7 +45,8 @@ typedef enum {
     TOKEN_LE,
     TOKEN_GT,
     TOKEN_LT,
-    TOKEN_ACCESS
+    TOKEN_ACCESS,
+    TOKEN_IN
 } token_type_t;
 
 typedef struct {

Modified: httpd/httpd/trunk/server/util_expr.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr.c?rev=1002415&r1=1002414&r2=1002415&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr.c (original)
+++ httpd/httpd/trunk/server/util_expr.c Tue Sep 28 23:26:44 2010
@@ -389,6 +389,13 @@ static int get_ptoken(apr_pool_t *pool, 
             return 0;
         }
         break;
+    case 'I':
+        if (**parse == 'N') {
+            TYPE_TOKEN(token, TOKEN_IN);
+            ++*parse;
+            return 0;
+        }
+        break;
     }
 
     /* It's a string or regex token
@@ -604,6 +611,7 @@ AP_DECLARE(ap_parse_node_t*) ap_expr_par
         case TOKEN_GT:
         case TOKEN_LE:
         case TOKEN_LT:
+        case TOKEN_IN:
             if (current->token.type == TOKEN_STRING) {
                 current = current->parent;
 
@@ -819,6 +827,27 @@ static int expr_eval(request_rec *r, ap_
             default: current->value = 0; break; /* should not happen */
             }
             break;
+        case TOKEN_IN:
+            if (!current->left || !current->right ||
+                current->left->token.type != TOKEN_STRING ||
+                current->right->token.type != TOKEN_STRING) {
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
+                              "Invalid expression in file %s", r->filename);
+                *was_error = 1;
+                return 0;
+            }
+
+            lval = PARSE_STRING(r, current->left->token.value);
+            rval = PARSE_STRING(r, current->right->token.value);
+            val = strstr(rval, lval);
+            /* should be included as a complete word, not a subword
+             * as in regexp /\bLVAL\b/
+             */
+            current->value = (val != NULL
+                              && (val == rval || !isalnum(val[-1]))
+                              && !isalnum(val[strlen(val)]))
+                ? 1 : 0;
+            break;
 
         case TOKEN_NOT:
         case TOKEN_GROUP:
@@ -941,7 +970,7 @@ AP_DECLARE_NONSTD(const char*) ap_expr_s
         char *ch, *var;
         apr_time_exp_t tm;
 
-        var = apr_pstrndup(r->pool, str+2, p-str-3);
+        var = apr_pstrndup(r->pool, str+2, p-str-2);
         for (ch = var; *ch; ++ch) {
             *ch = apr_toupper(*ch);
         }



Mime
View raw message