Macros

Top  Previous  Next

Macros can be used in any logical expressions; however, each macro must be predefined before use. They are defined in the Definitions section on the Filtering page. The [def] line must precede the macros definition.

Macro definition syntax:

macro_name = { BOOL_EXPR }

where BOOL_EXPR is a logical expression.

All macros return a Boolean value, arguments are not supported. In fact, a macro is just a shorthand notation for an logical expression.

Example:

Definition of the is_localhost and local_ip macros: they are to be true if the request was sent from one of the specified IP addresses or from one of the IP addresses listed in the file.

[def]
is_localhost = { request_ip <<= "127.0.0.0/8" }
 
local_ip = {
 request_ip <<= "127.0.0.0/8"
 || request_ip <<= "192.168.0.0/16"
 || request_ip <<= "172.16.0.0/12"
 || request_ip <<= file:"/tmp/icapd/other_local_ips.txt"
}

Definition of a worktime() macro: if the current system time is between 9:30 and 13:00 or 14:00 and 18:15, the macro is to be true.

[def]
worktime = {
(system_time>="9:30" && system_time<="13:00")
||
(system_time>="14:00" && system_time<"18:15")
}