{
parse_node_t *new, *root = NULL, *current = NULL;
request_rec *r = ctx->intern->r;
- const char* buffer;
+ const char *buffer, *error = "Invalid expression \"%s\" in file %s";
const char *parse = expr;
- int retval = 0, was_unmatched = 0;
+ int was_unmatched = 0;
unsigned regex = 0;
*was_error = 0;
continue;
default:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Invalid expression \"%s\" in file %s",
- expr, r->filename);
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, error, expr,
+ r->filename);
*was_error = 1;
- return retval;
+ return 0;
}
}
apr_pstrcat(ctx->dpool, current->token.value,
*current->token.value ? " " : "",
new->token.value, NULL);
- break;
+ continue;
case TOKEN_RE:
case TOKEN_RBRACE:
case TOKEN_GROUP:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Invalid expression \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
+ break;
default:
new->parent = current;
current = current->right = new;
- break;
+ continue;
}
break;
new->parent = current;
current = current->right = new;
++regex;
- break;
+ continue;
default:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Invalid expression \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
+ break;
}
break;
break;
case TOKEN_RBRACE:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Invalid expression \"%s\" in file %s",
- expr, r->filename);
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, error, expr,
+ r->filename);
*was_error = 1;
- return retval;
+ return 0;
default:
current = current->parent;
new->parent = current;
}
current = new;
- break;
+ continue;
case TOKEN_EQ:
case TOKEN_NE:
break;
}
}
-
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Invalid expression \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
+ break;
case TOKEN_RBRACE:
while (current && current->token.type != TOKEN_LBRACE) {
current = current->parent;
}
- if (!current) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Unmatched ')' in \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
+ if (current) {
+ TYPE_TOKEN(¤t->token, TOKEN_GROUP);
+ continue;
}
- TYPE_TOKEN(¤t->token, TOKEN_GROUP);
+ error = "Unmatched ')' in \"%s\" in file %s";
break;
case TOKEN_NOT:
case TOKEN_RE:
case TOKEN_RBRACE:
case TOKEN_GROUP:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Invalid expression \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
+ break;
default:
- break;
+ current->right = new;
+ new->parent = current;
+ current = new;
+ continue;
}
-
- current->right = new;
- new->parent = current;
- current = new;
break;
default:
break;
}
+
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, error, expr, r->filename);
+ *was_error = 1;
+ return 0;
}
DEBUG_DUMP_TREE(ctx, root);
/* Evaluate Parse Tree */
current = root;
+ error = NULL;
while (current) {
switch (current->token.type) {
case TOKEN_STRING:
current->token.value = buffer;
current->value = !!*current->token.value;
- DEBUG_DUMP_EVAL(ctx, current);
- current->done = 1;
- current = current->parent;
break;
- case TOKEN_RE:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "No operator before regex of expr \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
-
case TOKEN_AND:
case TOKEN_OR:
if (!current->left || !current->right) {
"Invalid expression \"%s\" in file %s",
expr, r->filename);
*was_error = 1;
- return retval;
+ return 0;
}
if (!current->right->done) {
current->right->value;
}
}
-
- DEBUG_DUMP_EVAL(ctx, current);
- current->done = 1;
- current = current->parent;
break;
case TOKEN_EQ:
"Invalid expression \"%s\" in file %s",
expr, r->filename);
*was_error = 1;
- return retval;
+ return 0;
}
buffer = ap_ssi_parse_string(ctx, current->left->token.value,
NULL, 0, SSI_EXPAND_DROP_NAME);
if (current->token.type == TOKEN_NE) {
current->value = !current->value;
}
-
- DEBUG_DUMP_EVAL(ctx, current);
- current->done = 1;
- current = current->parent;
break;
case TOKEN_GE:
"Invalid expression \"%s\" in file %s",
expr, r->filename);
*was_error = 1;
- return retval;
+ return 0;
}
buffer = ap_ssi_parse_string(ctx, current->left->token.value, NULL,
0, SSI_EXPAND_DROP_NAME);
current->value = strcmp(current->left->token.value,
current->right->token.value);
- if (current->token.type == TOKEN_GE) {
- current->value = current->value >= 0;
- }
- else if (current->token.type == TOKEN_GT) {
- current->value = current->value > 0;
- }
- else if (current->token.type == TOKEN_LE) {
- current->value = current->value <= 0;
- }
- else if (current->token.type == TOKEN_LT) {
- current->value = current->value < 0;
- }
- else {
- current->value = 0; /* Don't return -1 if unknown token */
+ switch (current->token.type) {
+ case TOKEN_GE: current->value = current->value >= 0; break;
+ case TOKEN_GT: current->value = current->value > 0; break;
+ case TOKEN_LE: current->value = current->value <= 0; break;
+ case TOKEN_LT: current->value = current->value < 0; break;
+ default: current->value = 0; break; /* should not happen */
}
-
- DEBUG_DUMP_EVAL(ctx, current);
- current->done = 1;
- current = current->parent;
break;
case TOKEN_NOT:
- if (current->right) {
- if (!current->right->done) {
- current = current->right;
- continue;
- }
- current->value = !current->right->value;
- }
- else {
- current->value = 0;
- }
-
- DEBUG_DUMP_EVAL(ctx, current);
- current->done = 1;
- current = current->parent;
- break;
-
case TOKEN_GROUP:
if (current->right) {
if (!current->right->done) {
current->value = 1;
}
- DEBUG_DUMP_EVAL(ctx, current);
- current->done = 1;
- current = current->parent;
+ if (current->token.type == TOKEN_NOT) {
+ current->value = !current->value;
+ }
break;
+ case TOKEN_RE:
+ if (!error) {
+ error = "No operator before regex in expr \"%s\" in file %s";
+ }
case TOKEN_LBRACE:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "Unmatched '(' in \"%s\" in file %s",
- expr, r->filename);
- *was_error = 1;
- return retval;
-
+ if (!error) {
+ error = "Unmatched '(' in \"%s\" in file %s";
+ }
default:
- ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
- "bad token type (internal parser error)");
+ if (!error) {
+ error = "internal parser error in \"%s\" in file %s";
+ }
+
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, error, expr,r->filename);
*was_error = 1;
- return retval;
+ return 0;
}
+
+ DEBUG_DUMP_EVAL(ctx, current);
+ current->done = 1;
+ current = current->parent;
}
return (root ? root->value : 0);