[OpenSIPS-Users] [NEW] New Pseudo-Variables (branch and contacts manipulation)
Bogdan-Andrei Iancu
bogdan at voice-system.ro
Mon Jul 6 13:24:53 CEST 2009
Hi,
OpenSIPS 1.6 (current trunk) comes with new additions to the
Pseudo-Variables set:
1) Message Contact processing
------------------------------
$ct - **reference to contact instance/body from the contact header. A
contact instance is "display_name + URI + contact_params" or "*" . As a
Contact header may contain multiple Contact instances and a message may
contain multiple Contact headers, an index was added to the $ct variable:
* $ct -first contact instance from message
* $(ct[n]) - the n-th contact instance form the beginning of
message, starting with index 0
* $(ct[-n]) - the n-th contact instance form the end of the message,
starting with index -1 (the last contact instance)
$ct.fields() - reference to the sub-fields of a contact instance/body
(see above). Supported fields are:
* name - display name
* uri - contact uri
* q - q param (value only)
* expires - expires param (value only)
* methods - methods param (value only)
* received - received param (value only)
* params - all params (including names)
Scenario Example - iterate through all contacts of a REGISTER, to check
the registered contacts:
$var(i) = 0;
while( $(ct[$var(i)])!=NULL ) {
if ( (ct.fields(uri)[$var(i)])!=NULL )
xlog("-------contact $var(i) -> $(ct.fields(uri)[$var(i)])\n");
if ( $(ct.fields(uri)[$var(i)]{uri.host})=="192.168.10.5" ) {
sl_send_reply("401","Forbidden IP in contact");
exit;
}
} else {
xlog("-------contact $var(i) is STAR\n")
}
$var(i) = $var(i) + 1;
}
2) Branch processing
---------------------
$branch - simple variable to write into in order to create a new branch:
$branch = "sip:user at domain.org";
$(branch(fields)[N]) - this variable provides read/write access to all
fields/attributes of an already existing branch (priorly created with
append_branch() ). The fields of the branch are:
* uri - the RURI of the branch (string value)
* duri - destination URI of the branch (outbound proxy of the
branch) (string value)
* q - q value of the branch (int value)
* path - the PATH string for this branch (string value)
* flags - the branch flags of this branch (int value)
* socket - the local socket to be used for relaying this branch
(string value)
The variable accepts also index *$(branch(uri)[1])* for accessing a
specific branch (multiple branches can be defined at a moment). The
index starts from 0 (first branch). If the index is negative, it is
considered the n-th branch from the end ( index -1 means the last branch).
To get all branches, use the * index - $(branch(uri)[*]).
This pseudo-variable was introduce to solve the need of inspecting and
changing the branches that were automatically added by module functions
(like uac_redirect, registrar, lcr, etc).
Usage Example:
# creates the first branch
$branch = "sip:tester at opensips.org";
# creates the second branch
force_send_socket(udp:192.168.1.10:5060);
$du = "sip:192.168.2.10";
append_branch("sip:foo at bar.com","0.5");
# display branches
xlog("----- branch 0: $(branch(uri)[0]) , $(branch(q)[0]),
$(branch(duri)[0]), $(branch(path)[0]), $(branch(flags)[0]),
$(branch(socket)[0]) \n");
xlog("----- branch 1: $(branch(uri)[1]) , $(branch(q)[1]),
$(branch(duri)[1]), $(branch(path)[1]), $(branch(flags)[1]),
$(branch(socket)[1]) \n");
# do some changes over the branches
$branch(uri) = "sip:user at domain.ro"; # change the URI for the first
branch
$(branch(q)[0]) = 1000; # change q to 1.00 for the first branch
$(branch(socket)[1]) = NULL; # reset the socket of the second branch
$branch(duri) = NULL; # reset the destination URI of the first branch
Scenario Example - iterate through all existing branches and display them:
if (lookup("location")) {
$var(i) = 0;
while( $(brnach(uri)[$var(i)])!=NULL ) {
xlog("-------branch $var(i) -> $(branch(uri)[$var(i)])\n");
$var(i) = $var(i) + 1;
}
}
3) Startup time stamp
----------------------
$TS - unix timestamp for the
Regards,
Bogdan
More information about the Users
mailing list