Add trace output in filtering process
This commit is contained in:
parent
191f049ea8
commit
846de028cf
1 changed files with 83 additions and 50 deletions
|
@ -306,64 +306,88 @@ pub mod header_filter_lang {
|
||||||
match *self.0 {
|
match *self.0 {
|
||||||
CO::OpIs => match self.1 {
|
CO::OpIs => match self.1 {
|
||||||
&CV::Values(_) => error_exit("Cannot check whether a header field is the same type as mulitple values!"),
|
&CV::Values(_) => error_exit("Cannot check whether a header field is the same type as mulitple values!"),
|
||||||
&CV::Value(ref v) => match v {
|
&CV::Value(ref v) => {
|
||||||
&Value::Boolean(_) => is_match!(*val, TVal::Boolean(_)),
|
trace!("Checking whether {:?} and {:?} have same type", v, val);
|
||||||
&Value::Integer(_) => is_match!(*val, TVal::Integer(_)),
|
match v {
|
||||||
&Value::String(_) => is_match!(val, &TVal::String(_)),
|
&Value::Boolean(_) => is_match!(*val, TVal::Boolean(_)),
|
||||||
|
&Value::Integer(_) => is_match!(*val, TVal::Integer(_)),
|
||||||
|
&Value::String(_) => is_match!(val, &TVal::String(_)),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
CO::OpIn => match (self.1, val) {
|
CO::OpIn => {
|
||||||
(&CV::Value(Value::Boolean(i)), &TVal::Boolean(j)) => i == j,
|
trace!("Checking whether {:?} is in {:?}", self.1, val);
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i == j,
|
match (self.1, val) {
|
||||||
(&CV::Value(Value::String(ref s)), &TVal::String(ref b)) => s.contains(b),
|
(&CV::Value(Value::Boolean(i)), &TVal::Boolean(j)) => i == j,
|
||||||
(&CV::Value(_), _) => false,
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i == j,
|
||||||
|
(&CV::Value(Value::String(ref s)), &TVal::String(ref b)) => s.contains(b),
|
||||||
|
(&CV::Value(_), _) => false,
|
||||||
|
|
||||||
(&CV::Values(ref v), &TVal::Integer(j)) => v.iter().any(|e| match e {
|
(&CV::Values(ref v), &TVal::Integer(j)) => v.iter().any(|e| match e {
|
||||||
&Value::Integer(i) => i == j,
|
&Value::Integer(i) => i == j,
|
||||||
_ => false
|
_ => false
|
||||||
}),
|
}),
|
||||||
(&CV::Values(ref v), &TVal::String(ref b)) => v.iter().any(|e| match e {
|
(&CV::Values(ref v), &TVal::String(ref b)) => v.iter().any(|e| match e {
|
||||||
&Value::String(ref s) => s == b,
|
&Value::String(ref s) => s == b,
|
||||||
_ => false
|
_ => false
|
||||||
}),
|
}),
|
||||||
(&CV::Values(_), _) => false,
|
(&CV::Values(_), _) => false,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CO::OpEq => match (self.1, val) {
|
CO::OpEq => {
|
||||||
(&CV::Value(Value::Boolean(i)), &TVal::Boolean(j)) => i == j,
|
trace!("Checking whether {:?} == {:?}", self.1, val);
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i == j,
|
match (self.1, val) {
|
||||||
(&CV::Value(Value::String(ref s)), &TVal::String(ref b)) => s == b,
|
(&CV::Value(Value::Boolean(i)), &TVal::Boolean(j)) => i == j,
|
||||||
(&CV::Value(_), _) => false,
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i == j,
|
||||||
(&CV::Values(_), _) => error_exit("Cannot check a header field for equality to multiple header fields!"),
|
(&CV::Value(Value::String(ref s)), &TVal::String(ref b)) => s == b,
|
||||||
|
(&CV::Value(_), _) => false,
|
||||||
|
(&CV::Values(_), _) => error_exit("Cannot check a header field for equality to multiple header fields!"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CO::OpNeq => match (self.1, val) {
|
CO::OpNeq => {
|
||||||
(&CV::Value(Value::Boolean(i)), &TVal::Boolean(j)) => i != j,
|
trace!("Checking whether {:?} != {:?}", self.1, val);
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i != j,
|
match (self.1, val) {
|
||||||
(&CV::Value(Value::String(ref s)), &TVal::String(ref b)) => s != b,
|
(&CV::Value(Value::Boolean(i)), &TVal::Boolean(j)) => i != j,
|
||||||
(&CV::Value(_), _) => false,
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i != j,
|
||||||
(&CV::Values(_), _) => error_exit("Cannot check a header field for inequality to multiple header fields!"),
|
(&CV::Value(Value::String(ref s)), &TVal::String(ref b)) => s != b,
|
||||||
|
(&CV::Value(_), _) => false,
|
||||||
|
(&CV::Values(_), _) => error_exit("Cannot check a header field for inequality to multiple header fields!"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CO::OpGte => match (self.1, val) {
|
CO::OpGte => {
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i >= j,
|
trace!("Checking whether {:?} >= {:?}", self.1, val);
|
||||||
(&CV::Value(_), _) => false,
|
match (self.1, val) {
|
||||||
(&CV::Values(_), _) => error_exit("Cannot check a header field for greater_than_equal to multiple header fields!"),
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i >= j,
|
||||||
|
(&CV::Value(_), _) => false,
|
||||||
|
(&CV::Values(_), _) => error_exit("Cannot check a header field for greater_than_equal to multiple header fields!"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CO::OpLte => match (self.1, val) {
|
CO::OpLte => {
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i <= j,
|
trace!("Checking whether {:?} <= {:?}", self.1, val);
|
||||||
(&CV::Value(_), _) => false,
|
match (self.1, val) {
|
||||||
(&CV::Values(_), _) => error_exit("Cannot check a header field for lesser_than_equal to multiple header fields!"),
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i <= j,
|
||||||
|
(&CV::Value(_), _) => false,
|
||||||
|
(&CV::Values(_), _) => error_exit("Cannot check a header field for lesser_than_equal to multiple header fields!"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CO::OpLt => match (self.1, val) {
|
CO::OpLt => {
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i < j,
|
trace!("Checking whether {:?} < {:?}", self.1, val);
|
||||||
(&CV::Value(_), _) => false,
|
match (self.1, val) {
|
||||||
(&CV::Values(_), _) => error_exit("Cannot check a header field for lesser_than to multiple header fields!"),
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i < j,
|
||||||
|
(&CV::Value(_), _) => false,
|
||||||
|
(&CV::Values(_), _) => error_exit("Cannot check a header field for lesser_than to multiple header fields!"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
CO::OpGt => match (self.1, val) {
|
CO::OpGt => {
|
||||||
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i > j,
|
trace!("Checking whether {:?} > {:?}", self.1, val);
|
||||||
(&CV::Value(_), _) => false,
|
match (self.1, val) {
|
||||||
(&CV::Values(_), _) => {
|
(&CV::Value(Value::Integer(i)), &TVal::Integer(j)) => i > j,
|
||||||
error!("Cannot check a header field for greater_than to multiple header fields!");
|
(&CV::Value(_), _) => false,
|
||||||
exit(1)
|
(&CV::Values(_), _) => {
|
||||||
},
|
error!("Cannot check a header field for greater_than to multiple header fields!");
|
||||||
|
exit(1)
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,9 +397,12 @@ pub mod header_filter_lang {
|
||||||
fn filter(&self, entry: &Entry) -> bool {
|
fn filter(&self, entry: &Entry) -> bool {
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
|
||||||
|
let selector_str = self.selector.selector_str();
|
||||||
|
trace!("Filtering {} at {}", entry.get_location(), selector_str);
|
||||||
|
|
||||||
entry
|
entry
|
||||||
.get_header()
|
.get_header()
|
||||||
.read(self.selector.selector_str())
|
.read(selector_str)
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.map(|value| {
|
.map(|value| {
|
||||||
let comp = Comparator(&self.compare_operator, &self.compare_value);
|
let comp = Comparator(&self.compare_operator, &self.compare_value);
|
||||||
|
@ -433,21 +460,27 @@ pub mod header_filter_lang {
|
||||||
impl ::filters::filter::Filter<Entry> for Query {
|
impl ::filters::filter::Filter<Entry> for Query {
|
||||||
|
|
||||||
fn filter(&self, entry: &Entry) -> bool {
|
fn filter(&self, entry: &Entry) -> bool {
|
||||||
|
trace!("Filtering = {}", entry.get_location());
|
||||||
let mut res = self.filter.filter(entry);
|
let mut res = self.filter.filter(entry);
|
||||||
|
trace!("First filter = {}", res);
|
||||||
|
|
||||||
for &(ref operator, ref next) in self.next_filters.iter() {
|
for &(ref operator, ref next) in self.next_filters.iter() {
|
||||||
match *operator {
|
match *operator {
|
||||||
Operator::Or => {
|
Operator::Or => {
|
||||||
|
trace!("Operator = {} OR {:?}", res, next);
|
||||||
res = res || ::filters::filter::Filter::filter(next, entry);
|
res = res || ::filters::filter::Filter::filter(next, entry);
|
||||||
},
|
},
|
||||||
Operator::And => {
|
Operator::And => {
|
||||||
|
trace!("Operator = {} AND {:?}", res, next);
|
||||||
res = res && ::filters::filter::Filter::filter(next, entry);
|
res = res && ::filters::filter::Filter::filter(next, entry);
|
||||||
},
|
},
|
||||||
Operator::Xor => {
|
Operator::Xor => {
|
||||||
|
trace!("Operator = {} XOR {:?}", res, next);
|
||||||
let other = ::filters::filter::Filter::filter(next, entry);
|
let other = ::filters::filter::Filter::filter(next, entry);
|
||||||
res = (res && !other) || (!res && other);
|
res = (res && !other) || (!res && other);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
trace!("After applying next filter = {}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|
Loading…
Reference in a new issue