Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
utils:flags [2009/02/14 22:03] – 86.121.129.39 | utils:flags [2012/03/08 19:04] (current) – [Branch flags] typo yo -> you 93.82.96.163 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Kamailio (OpenSER) Flags description ====== | ||
+ | |||
+ | ===== Types of flags ===== | ||
+ | |||
+ | * **message flags** (or transaction flags) will works as they do now, but the branch mask will be removed (rolling back as in 0.9.x versions). These flags are transaction persistent. | ||
+ | * **branch flags** (NEW) are saved also in transaction, | ||
+ | * **script flags** (NEW) are no-message-related flags - they are only script persistent and you can strictly use them for scripting. Once you exit a top level route, they will be lost. These flags are useful and they offer an option to de-congest the message flags - many flags have no need to be saved as they just reflect some scripting status. | ||
+ | |||
+ | |||
+ | ===== Corresponding Functions ===== | ||
+ | |||
+ | |||
+ | ==== Message/ | ||
+ | |||
+ | setflag(flag_idx) | ||
+ | resetflag(flag_idx) | ||
+ | isflagset(flag_idx) | ||
+ | |||
+ | ==== Branch flags ==== | ||
+ | |||
+ | setbflag/ | ||
+ | resetbflag/ | ||
+ | isbflagset/ | ||
+ | |||
+ | or, the shorter format, working on the default (branch 0) flags: | ||
+ | |||
+ | setbflag(flag_idx) | ||
+ | resetbflag(flag_idx) | ||
+ | isbflagset(flag_idx) | ||
+ | |||
+ | |||
+ | ==== Script flags ==== | ||
+ | |||
+ | setsflag/ | ||
+ | resetsflag/ | ||
+ | issflagset/ | ||
+ | |||
+ | |||
+ | ===== Flags and Pseudo Variables ===== | ||
+ | |||
+ | |||
+ | ==== Message/ | ||
+ | |||
+ | $mf - decimal value | ||
+ | $mF - hexa value | ||
+ | |||
+ | ==== Branch flags ==== | ||
+ | |||
+ | $bf - decimal value | ||
+ | $bF - hexa value | ||
+ | ==== Script flags ==== | ||
+ | |||
+ | $sf - decimal value | ||
+ | $sF - hexa value | ||
+ | |||
+ | |||
+ | |||
+ | ===== Flags and routes ===== | ||
+ | |||
+ | |||
+ | |||
+ | ==== Message/ | ||
+ | |||
+ | |||
+ | These flags will show up in all routes where messages related to the initial request are processed. So, they will be visible and changeable in onbranch, failure and onreply routes; the flags will be visible in all branch routes; if you change a flag in a branch route, the next branch routes will inherit the change. | ||
+ | Message flag inheritance by the CANCEL (set flag in INVITE and see it in CANCEL req/reply), is known not to work. In Kamailio (OpenSER) 1.2 the CANCEL is a different transaction than the INVITE, but starting with 1.3 it is one transaction, | ||
+ | |||
+ | |||
+ | |||
+ | ==== Branch flags ==== | ||
+ | |||
+ | |||
+ | These flags will show up in all routes where messages related to initial branch request are processed. So, in branch route you will see different sets of flags (as they are different branches); in onreply route you will see the branch flags corresponding to the branch the reply belongs to; in failure route, the branch flags corresponding to the branch the winning reply belongs to will be visible. | ||
+ | In request route, you can have multiple branches (as a result of a lookup(), enum query, append_branch(), | ||
+ | ==== Script flags ==== | ||
+ | |||
+ | |||
+ | These flags are available only in script and are reset after each top level route execution (routes internally triggered by Kamailio (OpenSER)). They will be persistent per main route, onreply_route, | ||
+ | |||
+ | |||
+ | |||
+ | ===== Example ===== | ||
+ | |||
+ | |||
+ | ==== Nat flag handling ==== | ||
+ | |||
+ | < | ||
+ | | ||
+ | # 3 - the nat flag | ||
+ | | ||
+ | | ||
+ | |||
+ | route { | ||
+ | | ||
+ | if (nat detected) | ||
+ | setbflag(3); | ||
+ | |||
+ | | ||
+ | if (is_method(" | ||
+ | # the branch flags (including 3) will be saved into location | ||
+ | save(" | ||
+ | exit; | ||
+ | } else { | ||
+ | # lookup will load the branch flag from location | ||
+ | if (!lookup(" | ||
+ | | ||
+ | exit; | ||
+ | } | ||
+ | t_on_branch(" | ||
+ | t_relay(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | if (isbflagset(3)) { | ||
+ | #current branch is marked as natted | ||
+ | ......... | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | if no parallel forking is done, you can get rid of the branch route and add instead of t_on_branch(): | ||
+ | < | ||
+ | | ||
+ | if (isbflagset(3)) { | ||
+ | #current branch is marked as natted | ||
+ | ......... | ||
+ | } | ||
+ | | ||
+ | </ | ||
+ | |||
+ | ==== Utils Stuff ==== | ||
+ | |||
+ | {{indexmenu> |