Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 = Filter syntax =
6
7 For all modules, you can define a filter expression which will be evaluated for each SIP message coming.
8 If the filter matched, the message goes through the module, otherwise it is skipped.
9
10 For instance, this filter:
11
12 {{code}}
13 filter=from.uri.domain contains 'sip.linphone.org'
14 {{/code}}
15
16 Will only allow the module to see messages that come from the sip.linphone.org domain.
17
18 The filter syntax is quite specific to Flexisip. It allows to peek into the SIP messages and see some of their data. You manipulate variables and test them against other variables or constants.
19
20 == Literals ==
21
22 Literals include the following types:
23
24 |=(% scope="row" %)Strings|write them surrounded by single quotes: {{code}}'linphone.org'{{/code}}
25 |=List of strings|whitespace separated words: {{code}}toto titi tata{{/code}}
26 |=integers|write them normally: {{code}}5223{{/code}}
27 |=Parenthesis|used to separate different nested expressions: {{code}}( from.uri.user == 'toto' ) || (from.uri.user == 'titi'){{/code}}
28 |=Booleans|{{code}}true{{/code}} and {{code}}false{{/code}}
29
30 == Variables ==
31
32 |=(% scope="row" %)from.uri.domain |(((
33 The domain set in the //From~:// header. For instance,
34 {{code}}From: <sip:toto@titi;param1=3>{{/code}} has domain {{code}}titi{{/code}}
35 )))
36 |=from.uri.user |The username set in the //From~:// header. In the above example, user is //toto//
37 |=from.uri.params |The parameters that are appended to the uri of the //From~:// header. Above example would result in //param1=3//
38 |=to.uri.[domain,user,params] |Same as above, but in the //To~:// header
39 |=request.uri.[domain,user,params] |Same as above, but in the case of the request.
40 |=request.method|The method of the request (REGISTER, SUBSCRIBE, ...)
41 |=direction |Gives the direction of the message. Returns 'request' or 'response'
42 |=status.phrase |For responses, gives the status phrase ("Registration Successful" for instance)
43 |=status.code |For responses, gives the status code
44 |=user-agent |For requests, gives the user-agent string
45 |=call-id |The call id of the SIP message
46 |=call-id.hash |The call id hash of the SIP message
47
48 == Operators and keywords ==
49
50 The operators mostly work with 2 arguments (left-hand-side and right-hand-side).
51 Some of them only take one argument: {{code}}numeric{{/code}} and {{code}}defined{{/code}}.
52 {{code}}is_response{{/code}} and {{code}}is_request{{/code}} take no argument.
53
54 Here is the list of the available operators:
55
56 |=Operator|=Description|=(% colspan="2" %)Example
57 |~|~||Logical OR |(% colspan="2" %){{code}}(to.uri.domain contains 'linphone') || (from.uri.domain contains 'linphone'){{/code}}
58 |&&|Logical AND|(% colspan="2" %){{code}}(to.uri.domain contains 'linphone') && (from.uri.domain contains 'linphone'){{/code}}
59 |(% colspan="1" rowspan="2" %)! |(% colspan="1" rowspan="2" %)Logical NOT|{{code}}!is_request{{/code}}
60 |{{code}}!(from.uri.username regex '[a-z]+'){{/code}}
61 |defined |Tests if the variable is defined |(% colspan="2" %){{code}}defined from.uri.user{{/code}}
62 |contains |Tests if the variable contains the element on right hand side |(% colspan="2" %){{code}}from.uri.domain contains 'linphone'{{/code}}
63 |regex |(((
64 Tests the left hand side with a regex defined on the right.
65
66 The regex grammar used is [[the implementation of the ECMAScript grammar by C++>>https://en.cppreference.com/w/cpp/regex/ecmascript]].
67
68 Note that the filter will only be successful if it match the //entire// character sequence.
69 )))|(% colspan="2" %){{code}}from.uri.username regex '[a-z]+'{{/code}}
70 |in |Tests the presence of the LHS string in the RHS string list |(% colspan="2" %){{code}}from.uri.username in 'toto titi'{{/code}}
71 |notin |Tests the absence of the LHS string in the RHS string list |(% colspan="2" %){{code}}from.uri.username notin 'toto titi'{{/code}}
72 |numeric |Tests if the RHS is numeric |(% colspan="2" %){{code}}numeric status.code{{/code}}
73 |is_request |Special keyword for testing if the message is a request |(% colspan="2" %){{code}}is_request && request.method-name == 'REGISTER'{{/code}}
74 |is_response |Special keyword to test if the message is a response |(% colspan="2" %){{code}}is_response && status.code == 200{{/code}}