3
A brief file description
5
@section license License
7
Licensed to the Apache Software Foundation (ASF) under one
8
or more contributor license agreements. See the NOTICE file
9
distributed with this work for additional information
10
regarding copyright ownership. The ASF licenses this file
11
to you under the Apache License, Version 2.0 (the
12
"License"); you may not use this file except in compliance
13
with the License. You may obtain a copy of the License at
15
http://www.apache.org/licenses/LICENSE-2.0
17
Unless required by applicable law or agreed to in writing, software
18
distributed under the License is distributed on an "AS IS" BASIS,
19
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
See the License for the specific language governing permissions and
21
limitations under the License.
29
#include "LogAccess.h"
31
#include "LogFormat.h"
33
/*-------------------------------------------------------------------------
36
This is an abstract base class from which particular filters can be
37
derived. Each filter must implement the "toss_this_entry" member
38
function which, given a LogAccess object, returns true if
39
the log entry is to be tossed out.
40
-------------------------------------------------------------------------*/
59
static const char *ACTION_NAME[];
61
// all operators "positive" (i.e., there is no NOMATCH operator anymore)
62
// because one can specify through the "action" field if the record should
63
// be kept or tossed away
68
CASE_INSENSITIVE_MATCH,
70
CASE_INSENSITIVE_CONTAIN,
73
static const char *OPERATOR_NAME[];
75
LogFilter(const char *name, LogField * field, Action action, Operator oper);
76
virtual ~ LogFilter();
78
char *name() const { return m_name; }
79
Type type() const { return m_type; }
80
size_t get_num_values() const { return m_num_values; };
82
virtual bool toss_this_entry(LogAccess * lad) = 0;
83
virtual void display(FILE * fd = stdout) = 0;
84
virtual void display_as_XML(FILE * fd = stdout) = 0;
88
m_action = (m_action == REJECT ? ACCEPT : REJECT);
94
Action m_action; // the action this filter takes
97
size_t m_num_values; // the number of comparison values
100
LINK(LogFilter, link); // so we can create a LogFilterList
103
// -- member functions that are not allowed --
105
LogFilter(const LogFilter & rhs);
106
LogFilter & operator=(LogFilter & rhs);
109
/*-------------------------------------------------------------------------
112
Filter for string fields.
113
-------------------------------------------------------------------------*/
115
class LogFilterString:public LogFilter
118
LogFilterString(const char *name, LogField * field, Action a, Operator o, char *value);
119
LogFilterString(const char *name, LogField * field, Action a, Operator o, size_t num_values, char **value);
120
LogFilterString(const LogFilterString & rhs);
122
bool operator==(LogFilterString & rhs);
124
bool toss_this_entry(LogAccess * lad);
125
void display(FILE * fd = stdout);
126
void display_as_XML(FILE * fd = stdout);
129
char **m_value; // the array of values
131
// these are used to speed up case insensitive operations
133
char **m_value_uppercase; // m_value in all uppercase
134
size_t *m_length; // length of m_value string
136
void _setValues(size_t n, char **value);
138
// note: OperatorFunction's must return 0 (zero) if condition is satisfied
140
typedef int (*OperatorFunction) (const char *, const char *);
142
static int _isSubstring(const char *s0, const char *s1)
144
// return 0 if s1 is substring of s0 and 1 otherwise
145
// this reverse behavior is to conform to the behavior of strcmp
146
// which returns 0 if strings match
147
return (strstr(s0, s1) == NULL ? 1 : 0);
152
DATA_LENGTH_EQUAL = 0,
156
inline bool _checkCondition(OperatorFunction f,
157
const char *field_value, size_t field_value_length, char **val, LengthCondition lc);
159
// -- member functions that are not allowed --
161
LogFilterString & operator=(LogFilterString & rhs);
164
/*-------------------------------------------------------------------------
167
Filter for int fields.
168
-------------------------------------------------------------------------*/
170
class LogFilterInt:public LogFilter
173
LogFilterInt(const char *name, LogField * field, Action a, Operator o, int64_t value);
174
LogFilterInt(const char *name, LogField * field, Action a, Operator o, size_t num_values, int64_t *value);
175
LogFilterInt(const char *name, LogField * field, Action a, Operator o, char *values);
176
LogFilterInt(const LogFilterInt & rhs);
178
bool operator==(LogFilterInt & rhs);
180
bool toss_this_entry(LogAccess * lad);
181
void display(FILE * fd = stdout);
182
void display_as_XML(FILE * fd = stdout);
185
int64_t *m_value; // the array of values
187
void _setValues(size_t n, int64_t *value);
188
int _convertStringToInt(char *val, unsigned *ival, LogFieldAliasMap * map);
190
// -- member functions that are not allowed --
192
LogFilterInt & operator=(LogFilterInt & rhs);
195
bool filters_are_equal(LogFilter * filt1, LogFilter * filt2);
198
/*-------------------------------------------------------------------------
200
-------------------------------------------------------------------------*/
206
bool operator==(LogFilterList &);
208
void add(LogFilter * filter, bool copy = true);
209
bool toss_this_entry(LogAccess * lad);
210
LogFilter *find_by_name(char *name);
213
LogFilter *first() const { return m_filter_list.head; }
214
LogFilter *next(LogFilter * here) const { return (here->link).next; }
217
void display(FILE * fd = stdout);
218
void display_as_XML(FILE * fd = stdout);
220
bool does_conjunction() const { return m_does_conjunction; };
221
void set_conjunction(bool c) { m_does_conjunction = c; };
224
Queue<LogFilter> m_filter_list;
226
bool m_does_conjunction;
227
// If m_does_conjunction = true
228
// toss_this_entry returns true
229
// if ANY filter tosses entry away.
230
// If m_does_conjunction = false,
231
// toss this entry returns true if
232
// ALL filters toss away entry
234
// -- member functions that are not allowed --
235
LogFilterList(const LogFilterList & rhs);
236
LogFilterList & operator=(const LogFilterList & rhs);
240
/*-------------------------------------------------------------------------
242
-------------------------------------------------------------------------*/
244
/*-------------------------------------------------------------------------
247
check all values for a matching condition
249
the arguments to the function are:
251
- a function f of type OperatorFunction that determines if the
252
condition is true for a single filter value. Note that this function
253
must return 0 if the condition is true.
254
- the value of the field from the log record
255
- the length of this field
256
- the array of filter values to compare to note that we pass this as an
257
argument because it can be either m_value or m_value_uppercase
258
- a LengthCondition argument that determines if the length of the field value
259
must be equal or larger to the length of the filter value (this is to
260
compare strings only if really needed
261
------------------------------------------------------------------------*/
264
LogFilterString::_checkCondition(OperatorFunction f,
265
const char *field_value, size_t field_value_length, char **val, LengthCondition lc)
269
// make single value case a little bit faster by taking it out of loop
271
if (m_num_values == 1) {
273
case DATA_LENGTH_EQUAL:
274
retVal = (field_value_length == *m_length ? ((*f) (field_value, *val) == 0 ? true : false) : false);
276
case DATA_LENGTH_LARGER:
277
retVal = (field_value_length > *m_length ? ((*f) (field_value, *val) == 0 ? true : false) : false);
280
ink_assert(!"LogFilterString::checkCondition " "unknown LengthCondition");
285
case DATA_LENGTH_EQUAL:
286
for (i = 0; i < m_num_values; ++i) {
287
// condition is satisfied if f returns zero
288
if (field_value_length == m_length[i] && (*f) (field_value, val[i]) == 0) {
294
case DATA_LENGTH_LARGER:
295
for (i = 0; i < m_num_values; ++i) {
296
// condition is satisfied if f returns zero
297
if (field_value_length > m_length[i] && (*f) (field_value, val[i]) == 0) {
304
ink_assert(!"LogFilterString::checkCondition " "unknown LengthCondition");