added ^= (prefix match) and $= (suffix match) operators

personal/stbuehler/wip
Thomas Porzelt 14 years ago
parent b1c39dde0f
commit f795f2463a
  1. 1
      src/base.h
  2. 20
      src/condition.c
  3. 4
      src/condition.h
  4. 4
      src/config_parser.rl
  5. 1
      src/log.c

@ -38,7 +38,6 @@ typedef struct connection connection;
#include "connection.h"
#include "plugin_core.h"
#define SERVER_VERSION ((guint) 0x01FF0000)

@ -111,6 +111,8 @@ condition* condition_new_string(server *srv, comp_operator_t op, condition_lvalu
switch (op) {
case CONFIG_COND_EQ:
case CONFIG_COND_NE:
case CONFIG_COND_PREFIX:
case CONFIG_COND_SUFFIX:
return cond_new_string(op, lvalue, str);
case CONFIG_COND_MATCH:
case CONFIG_COND_NOMATCH:
@ -139,6 +141,8 @@ condition* condition_new_string(server *srv, comp_operator_t op, condition_lvalu
condition* condition_new_int(server *srv, comp_operator_t op, condition_lvalue *lvalue, gint64 i) {
condition *c;
switch (op) {
case CONFIG_COND_PREFIX:
case CONFIG_COND_SUFFIX:
case CONFIG_COND_MATCH:
case CONFIG_COND_NOMATCH:
case CONFIG_COND_IP:
@ -203,6 +207,8 @@ const char* comp_op_to_string(comp_operator_t op) {
switch (op) {
case CONFIG_COND_EQ: return "==";
case CONFIG_COND_NE: return "!=";
case CONFIG_COND_PREFIX: return "^=";
case CONFIG_COND_SUFFIX: return "$=";
case CONFIG_COND_MATCH: return "=~";
case CONFIG_COND_NOMATCH: return "!~";
case CONFIG_COND_IP: return "=/";
@ -287,10 +293,16 @@ static gboolean condition_check_eval_string(server *srv, connection *con, condit
switch (cond->op) {
case CONFIG_COND_EQ:
result = (0 == strcmp(value, cond->rvalue.string->str));
result = g_str_equal(value, cond->rvalue.string->str);
break;
case CONFIG_COND_NE:
result = (0 != strcmp(value, cond->rvalue.string->str));
result = g_str_equal(value, cond->rvalue.string->str);
break;
case CONFIG_COND_PREFIX:
result = g_str_has_prefix(value, cond->rvalue.string->str);
break;
case CONFIG_COND_SUFFIX:
result = g_str_has_suffix(value, cond->rvalue.string->str);
break;
case CONFIG_COND_MATCH:
case CONFIG_COND_NOMATCH:
@ -344,6 +356,8 @@ static gboolean condition_check_eval_int(server *srv, connection *con, condition
return (value > cond->rvalue.i);
case CONFIG_COND_GE: /** >= */
return (value >= cond->rvalue.i);
case CONFIG_COND_PREFIX:
case CONFIG_COND_SUFFIX:
case CONFIG_COND_MATCH:
case CONFIG_COND_NOMATCH:
case CONFIG_COND_IP:
@ -458,6 +472,8 @@ static gboolean condition_check_eval_ip(server *srv, connection *con, condition
return ip_in_net(&ipval, &cond->rvalue);
case CONFIG_COND_NOTIP:
return !ip_in_net(&ipval, &cond->rvalue);
case CONFIG_COND_PREFIX:
case CONFIG_COND_SUFFIX:
case CONFIG_COND_EQ:
case CONFIG_COND_NE:
case CONFIG_COND_MATCH:

@ -20,6 +20,10 @@ typedef enum {
CONFIG_COND_EQ, /** == */
CONFIG_COND_NE, /** != */
/* only with string */
CONFIG_COND_PREFIX, /** ^= */
CONFIG_COND_SUFFIX, /** $= */
/* only usable with pcre */
CONFIG_COND_MATCH, /** =~ */
CONFIG_COND_NOMATCH, /** !~ */

@ -360,6 +360,8 @@
else if (*ctx->mark == '<' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_LE;
else if (*ctx->mark == '=' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_EQ;
else if (*ctx->mark == '!' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_NE;
else if (*ctx->mark == '^' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_PREFIX;
else if (*ctx->mark == '$' && *(ctx->mark+1) == '=') ctx->op = CONFIG_COND_SUFFIX;
else if (*ctx->mark == '=' && *(ctx->mark+1) == '~') ctx->op = CONFIG_COND_MATCH;
else if (*ctx->mark == '!' && *(ctx->mark+1) == '~') ctx->op = CONFIG_COND_NOMATCH;
}
@ -684,7 +686,7 @@
value_statement = ( value (ws* ('+'|'-'|'*'|'/') >value_statement_op ws* value %value_statement)? );
hash_elem = ( string >mark noise* ':' noise* value );
operator = ( '==' | '!=' | '<' | '<=' | '>' | '>=' | '=~' | '!~' ) >mark %operator;
operator = ( '==' | '!=' | '^=' | '$=' | '<' | '<=' | '>' | '>=' | '=~' | '!~' ) >mark %operator;
# statements
assignment = ( varname ws* '=' ws* value_statement ';' ) %assignment;

@ -1,5 +1,6 @@
#include "log.h"
#include "plugin_core.h"
#include <stdarg.h>
#if REMOVE_PATH_FROM_FILE

Loading…
Cancel
Save