Logic Expressions

Top  Previous  Next

Logical expressions are operations of function call united by the following operators: && - conjunction (logical AND), || - disjunction (logical OR), ! - negation (logical NOT). To group operations and change their priority, use brackets.

Внимание!

Only &&, || and ! operators can be used in a logical expression. Standard mnemonics (AND, OR, NOT) are not allowed.

Syntax of BOOL_EXPR logical expressions is as follows:

macro_name() | COMPARE |
(BOOL_EXPR) | !BOOL_EXPR |
BOOL_EXPR && BOOL_EXPR |
BOOL_EXPR || BOOL_EXPR

Where macro_name() is a call of macro with the macro_name name, and COMPARE is one of the comparison operations listed below. The macro must be defined in the Definitions section.

To define the COMPARE operation, you can use the following notations:

Notation

Description

string_var

cidr_var

time_var

Parameter of the corresponding type (STRING, CIDR or TIME)

TIME

String of the following format: "HH:MM" or "H:MM" (hours, minutes); must be enclosed in quotation marks

STRING

Random string enclosed in quotation marks

REGEX

Regular expression of the POSIX extended format; must be enclosed in quotation marks

FILE_NAME

File path enclosed in quotation marks

CIDR

IPv4 address enclosed in quotation marks (you can specify a network prefix after a stroke character). If the network prefix is not specified, it is treated equal to /32. An empty string "" indicates the special undefined value

The following comparison operations are supported for variables of the string type:

Operation

Description

string_var == STRING

Variable matches the string

string_var != STRING

Variable does not match the string

string_var ~ REGEX

Variable contains the substring that is checked for matching the regular expression (search method is used)

string_var == file:FILE_NAME

Variable matches at least one string in the specified file

string_var ~ file:FILE_NAME

Variable corresponds to at least one regular expression in the specified file

Note that == and ~ operations are case insensitive.

The following comparison operations are supported for variables of the cidr type:

Operation

Description

cidr_var <<= CIDR

IP address is within the specified network range

cidr_var <<= file:FILE_NAME

IP address is within at least one of the networks listed in the file

If both arguments of the <<= operation have the undefined value, the operation result is true. If only one parameter has the undefined value, the operation result is false.

The following comparison operations are supported for variables of the time type:

Operation

Description

time_var >  TIME

time_var >= TIME

time_var <  TIME

time_var <= TIME

Time comparison

Every operation has a certain priority relative to other operations. Sorted in descending order, comparison operation priority is as follows:

1.! ("logical NOT")

2.< ("less than"), <= ("less than or equal to"), > ("greater than"), >= ("greater than or equal to")

3.== ("equal to"), != ("not equal to"), ~ ("matches"), <<= ("belongs to")

4.&& ("logical AND")

5.|| ("logical OR")

Operations listed in the same line have equal priority and are processed from left to right.

For certain operations, reading of a value array from a file (specified with the file: prefix) is available. Lines beginning with the "#" or ";" characters as well as with empty lines are skipped when reading values.

Внимание!

The content of the file:FILE_NAME file is read while the configuration file is processed. Thus, after changing content of the file that contains values or a path to such a file, force Dr.Web ICAPD to reread its configuration, for example, by sending the SIGHUP signal.