Logical expressions

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.

Внимание!

Note that 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:

func_name() | COMPARE |
(BOOL_EXPR) | !BOOL_EXPR |
BOOL_EXPR && BOOL_EXPR |
BOOL_EXPR || BOOL_EXPR

Where BOOL_EXPR is a logical expression, func_name() is a call of function with the func_name name, and COMPARE is one of the comparison operations listed below. The function must be defined in the [def] section.

Comparison operation can be one of the following:

Notation

Description

string_var

cidr_var

time_var

Variable 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 mask after a stroke character). If the network mask is not specified, it is treated equal to /32. An empty string "" indicates an 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.

== 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 <<= operation have undefined value, the operation result is true. If only one parameter has 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 drweb-icapd to reread its configuration (for example, by sending the drweb-icapd daemon SIGHUP signal).