PERL module
Admin Guide
Section titled “Admin Guide”Overview
Section titled “Overview”The time needed when writing a new OpenSIPS module unfortunately is quite high, while the options provided by the configuration file are limited to the features implemented in the modules.
With this Perl module, you can easily implement your own OpenSIPS extensions in Perl. This allows for simple access to the full world of CPAN modules. SIP URI rewriting could be implemented based on regular expressions; accessing arbitrary data backends, e.g. LDAP or Berkeley DB files, is now extremely simple.
Installing the module
Section titled “Installing the module”This Perl module is loaded in opensips.cfg (just like all the other modules) with loadmodule(“/path/to/perl.so”);.
For the Perl module to compile, you need a reasonably recent version of perl (tested with 5.8.8) linked dynamically. It is strongly advised to use a threaded version. The default binary packages from your favorite Linux distribution should work fine.
Cross compilation is supported by the Makefile. You need to set the environment variables PERLLDOPTS, PERLCCOPTS and TYPEMAP to values similar to the output of
PERLLDOPTS: perl -MExtUtils::Embed -e ldoptsPERLCCOPTS: perl -MExtUtils::Embed -e ccoptsTYPEMAP: echo "`perl -MConfig -e 'print $Config{installprivlib}'`/ExtUtils/typemap"The exact position of your (precompiled!) perl libraries depends on the setup of your environment.
Using the module
Section titled “Using the module”The Perl module has two interfaces: The perl side, and the OpenSIPS side. Once a Perl function is defined and loaded via the module parameters (see below), it may be called in OpenSIPS’s configuration at an arbitary point. E.g., you could write a function “ldap_alias” in Perl, and then execute
...if (perl_exec("ldap_alias")) { ...}...just as you would have done with the current alias_db module.
The functions you can use are listed in the “Exported Functions” section below.
On the Perl side, there are a number of functions that let you read and modify the current SIP message, such as the RURI or the message flags. An introduction to the Perl interface and the full reference documentation can be found below.
Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”The following modules must be loaded before this module:
- The “sl” module is needed for sending replies uppon fatal errors. All other modules can be accessed from the Perl module, though.
External Libraries or Applications
Section titled “External Libraries or Applications”The following libraries or applications must be installed before running OpenSIPS with this module loaded:
- Perl 5.8.x or later
Additionally, a number of perl modules should be installed. The OpenSIPS::LDAPUtils package relies on Net::LDAP to be installed. One of the sample scripts needs IPC::Shareable
This module has been developed and tested with Perl 5.8.8, but should work with any 5.8.x release. Compilation is possible with 5.6.x, but its behavior is unsupported. Earlier versions do not work.
On current Debian systems, at least the following packages should be installed:
- perl
- perl-base
- perl-modules
- libperl5.8
- libperl-dev
- libnet-ldap-perl
- libipc-shareable-perl
It was reported that other Debian-style distributions (such as Ubuntu) need the same packages.
On SuSE systems, at least the following packages should be installed:
- perl
- perl-ldap
- IPC::Shareable perl module from CPAN
Although SuSE delivers a lot of perl modules, others may have to be fetched from CPAN. Consider using the program “cpan2rpm” - which, in turn, is available on CPAN. It creates RPM files from CPAN.
Exported Parameters
Section titled “Exported Parameters”filename (string)
Section titled “filename (string)”This is the file name of your script. This may be set once only, but it may include an arbitary number of functions and “use” as many Perl module as necessary.
May not be empty!
...modparam("perl", "filename", "/home/john/opensips/myperl.pl")...modpath (string)
Section titled “modpath (string)”The path to the Perl modules included (OpenSIPS.pm et.al). It is not absolutely crucial to set this path, as you may install the Modules in Perl’s standard path, or update the “%INC” variable from within your script. Using this module parameter is the standard behavior, though.
...modparam("perl", "modpath", "/usr/local/lib/opensips/perl/")...Exported Functions
Section titled “Exported Functions”perl_exec_simple(func, [param])
Section titled “perl_exec_simple(func, [param])”Calls a perl function without passing it the current SIP message. May be used for very simple simple requests that do not have to fiddle with the message themselves, but rather return information values about the environment.
The first parameter is the function to be called. An arbitrary string may optionally be passed as a parameter.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE and BRANCH_ROUTE.
...if (method=="INVITE") { perl_exec_simple("dosomething", "on invite messages");};...perl_exec(func, [param])
Section titled “perl_exec(func, [param])”Calls a perl function with passing it the current SIP message. The SIP message is reflected by a Perl module that gives you access to the information in the current SIP message (OpenSIPS::Message).
The first parameter is the function to be called. An arbitrary string may be passed as a parameter.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE and BRANCH_ROUTE.
...if (perl_exec("ldapalias")) { ...};...OpenSIPS Perl API
Section titled “OpenSIPS Perl API”OpenSIPS
Section titled “OpenSIPS”This module provides access to a limited number of OpenSIPS core functions. As the most interesting functions deal with SIP messages, they are located in the OpenSIPS::Message class below.
log(level,message)
Section titled “log(level,message)”Logs the message with OpenSIPS’s logging facility. The logging level is one of the following:
* L_ALERT* L_CRIT* L_ERR* L_WARN* L_NOTICE* L_INFO* L_DBGPlease note that this method is NOT automatically exported, as it collides
with the perl function log (which calculates the logarithm). Either
explicitly import the function (via use OpenSIPS qw ( log );), or call
it with its full name:
OpenSIPS::log(L_INFO, "foobar");OpenSIPS::Message
Section titled “OpenSIPS::Message”This package provides access functions for an OpenSIPS sip_msg structure and its
sub-components. Through its means it is possible to fully configure
alternative routing decisions.
getType()
Section titled “getType()”Returns one of the constants SIP_REQUEST, SIP_REPLY, SIP_INVALID stating the type of the current message.
getStatus()
Section titled “getStatus()”Returns the status code of the current Reply message. This function is invalid in Request context!
getReason()
Section titled “getReason()”Returns the reason of the current Reply message. This function is invalid in Request context!
getVersion()
Section titled “getVersion()”Returns the version string of the current SIP message.
getRURI()
Section titled “getRURI()”This function returns the recipient URI of the present SIP message:
my $ruri = $m->getRURI();
getRURI returns a string. See “getParsedRURI()” below how to receive a parsed structure.
This function is valid in request messages only.
getMethod()
Section titled “getMethod()”Returns the current method, such as INVITE, REGISTER, ACK and so on.
my $method = $m->getMethod();
This function is valid in request messages only.
getFullHeader()
Section titled “getFullHeader()”Returns the full message header as present in the current message. You might use this header to further work with it with your favorite MIME package.
my $hdr = $m->getFullHeader();
getBody()
Section titled “getBody()”Returns the message body.
getMessage()
Section titled “getMessage()”Returns the whole message including headers and body.
getHeader(name)
Section titled “getHeader(name)”Returns the body of the first message header with this name.
print $m->getHeader("To");
"John" <sip:john@doe.example>
getHeaderNames()
Section titled “getHeaderNames()”Returns an array of all header names. Duplicates possible!
moduleFunction(func,string1,string2)
Section titled “moduleFunction(func,string1,string2)”Search for an arbitrary function in module exports and call it with the parameters self, string1, string2.
string1 and/or string2 may be omitted.
As this function provides access to the functions that are exported to the OpenSIPS configuration file, it is autoloaded for unknown functions. Instead of writing
$m->moduleFunction("sl_send_reply", "500", "Internal Error");$m->moduleFunction("xlog", "L_INFO", "foo");you may as well write
$m->sl_send_reply("500", "Internal Error");$m->xlog("L_INFO", "foo");Here is a list of functions that are expected to be working (not claiming completeness):
- alias_db_lookup
- consume_credentials
- is_rpid_user_e164
- append_rpid_hf
- bind_auth
- avp_print
- cpl_process_register
- cpl_process_register_norpl
- load_dlg
- ds_next_dst
- ds_next_domain
- ds_mark_dst
- ds_mark_dst
- is_from_local
- is_uri_host_local
- dp_can_connect
- dp_apply_policy
- enum_query (without parameters)
- enum_fquery (without parameters)
- is_from_user_enum (without parameters)
- i_enum_query (without parameters)
- imc_manager
- jab_* (all functions from the jabber module)
- sdp_mangle_ip
- sdp_mangle_port
- encode_contact
- decode_contact
- decode_contact_header
- fix_contact
- use_media_proxy
- end_media_session
- m_store
- m_dump
- fix_nated_contact
- unforce_rtp_proxy
- force_rtp_proxy
- fix_nated_register
- add_rcv_param
- options_reply
- checkospheader
- validateospheader
- requestosprouting
- checkosproute
- prepareosproute
- prepareallosproutes
- checkcallingtranslation
- reportospusage
- mangle_pidf
- mangle_message_cpim
- add_path (without parameters)
- add_path_received (without parameters)
- prefix2domain
- allow_routing (without parameters)
- allow_trusted
- pike_check_req
- handle_publish
- handle_subscribe
- stored_pres_info
- bind_pua
- send_publish
- send_subscribe
- pua_set_publish
- loose_route
- record_route
- load_rr
- sip_trace
- sl_reply_error
- sms_send_msg
- sd_lookup
- sstCheckMin
- append_time
- has_body (without parameters)
- is_peer_verified
- t_newtran
- t_release
- t_relay (without parameters)
- t_flush_flags
- t_check_trans
- t_was_cancelled
- uac_restore_from
- uac_auth
- has_totag
- tel2sip
- check_to
- check_from
- radius_does_uri_exist
- ul_* (All functions exported by the usrloc module for user access)
- xmpp_send_message
log(level,message) (deprecated type)
Section titled “log(level,message) (deprecated type)”Logs the message with OpenSIPS’s logging facility. The logging level is one of the following:
- L_ALERT
- L_CRIT
- L_ERR
- L_WARN
- L_NOTICE
- L_INFO
- L_DBG
The logging function should be accessed via the OpenSIPS module variant. This one, located in OpenSIPS::Message, is deprecated.
rewrite_ruri(newruri)
Section titled “rewrite_ruri(newruri)”Sets a new destination (recipient) URI. Useful for rerouting the current message/call.
if ($m->getRURI() =~ m/\@somedomain.net/) { $m->rewrite_ruri("sip:dispatcher\@organization.net");}setFlag(flag)
Section titled “setFlag(flag)”Sets a message flag. The constants as known from the C API may be used, when Constants.pm is included.
resetFlag(flag)
Section titled “resetFlag(flag)”Resets a message flag.
isFlagSet(flag)
Section titled “isFlagSet(flag)”Returns whether a message flag is set or not.
pseudoVar(string)
Section titled “pseudoVar(string)”Returns a new string where all pseudo variables are substituted by their values. Can be used to receive the values of single variables, too.
Please remember that you need to escape the ’$’ sign in perl strings!
append_branch(branch,qval)
Section titled “append_branch(branch,qval)”Append a branch to current message.
serialize_branches(clean_before)
Section titled “serialize_branches(clean_before)”Serialize branches.
next_branches()
Section titled “next_branches()”Next branches.
getParsedRURI()
Section titled “getParsedRURI()”Returns the current destination URI as an OpenSIPS::URI object.
OpenSIPS::URI
Section titled “OpenSIPS::URI”This package provides functions for access to sip_uri structures.
user()
Section titled “user()”Returns the user part of this URI.
host()
Section titled “host()”Returns the host part of this URI.
passwd()
Section titled “passwd()”Returns the passwd part of this URI.
port()
Section titled “port()”Returns the port part of this URI.
params()
Section titled “params()”Returns the params part of this URI.
headers()
Section titled “headers()”Returns the headers part of this URI.
transport()
Section titled “transport()”Returns the transport part of this URI.
Returns the ttl part of this URI.
user_param()
Section titled “user_param()”Returns the user_param part of this URI.
maddr()
Section titled “maddr()”Returns the maddr part of this URI.
method()
Section titled “method()”Returns the method part of this URI.
Returns the lr part of this URI.
Returns the r2 part of this URI.
transport_val()
Section titled “transport_val()”Returns the transport_val part of this URI.
ttl_val()
Section titled “ttl_val()”Returns the ttl_val part of this URI.
user_param_val()
Section titled “user_param_val()”Returns the user_param_val part of this URI.
maddr_val()
Section titled “maddr_val()”Returns the maddr_val part of this URI.
method_val()
Section titled “method_val()”Returns the method_val part of this URI.
lr_val()
Section titled “lr_val()”Returns the lr_val part of this URI.
r2_val()
Section titled “r2_val()”Returns the r2_val part of this URI.
OpenSIPS::AVP
Section titled “OpenSIPS::AVP”This package provides access functions for OpenSIPS’s AVPs. These variables can be created, evaluated, modified and removed through this package.
Please note that these functions do NOT support the notation used in the configuration file, but directly work on strings or numbers. See documentation of add method below.
add(name,val)
Section titled “add(name,val)”Add an AVP.
Add an OpenSIPS AVP to its environment. name and val may both be integers or strings; this function will try to guess what is correct. Please note that
OpenSIPS::AVP::add("10", "10")is something different than
OpenSIPS::AVP::add(10, 10)due to this evaluation: The first will create string AVPs with the name 10, while the latter will create a numerical AVP.
You can modify/overwrite AVPs with this function.
get(name)
Section titled “get(name)”get an OpenSIPS AVP:
my $numavp = OpenSIPS::AVP::get(5);my $stravp = OpenSIPS::AVP::get("foo");destroy(name)
Section titled “destroy(name)”Destroy an AVP.
OpenSIPS::AVP::destroy(5);OpenSIPS::AVP::destroy("foo");OpenSIPS::Utils::PhoneNumbers
Section titled “OpenSIPS::Utils::PhoneNumbers”OpenSIPS::Utils::PhoneNumbers - Functions for canonical forms of phone numbers.
use OpenSIPS::Utils::PhoneNumbers;
my $phonenumbers = new OpenSIPS::Utils::PhoneNumbers( publicAccessPrefix => "0", internationalPrefix => "+", longDistancePrefix => "0", areaCode => "761", pbxCode => "456842", countryCode => "49" );
$canonical = $phonenumbers->canonicalForm("07612034567");$number = $phonenumbers->dialNumber("+497612034567");A telphone number starting with a plus sign and containing all dial prefixes is in canonical form. This is usally not the number to dial at any location, so the dialing number depends on the context of the user/system.
The idea to canonicalize numbers were taken from hylafax.
Example: +497614514829 is the canonical form of my phone number, 829 is the number to dial at Pyramid, 4514829 is the dialing number from Freiburg are and so on.
To canonicalize any number, we strip off any dial prefix we find and then add the prefixes for the location. So, when the user enters the number 04514829 in context pyramid, we remove the publicAccessPrefix (at Pyramid this is 0) and the pbxPrefix (4514 here). The result is 829. Then we add all the general dial prefixes - 49 (country) 761 (area) 4514 (pbx) and 829, the number itself => +497614514829
To get the dialing number from a canonical phone number, we substract all general prefixes until we have something
As said before, the interpretation of a phone number depends on the
context of the location. For the functions in this package, the
context is created through the new operator.
The following fields should be set:
'longDistancePrefix''areaCode''pbxCode''internationalPrefix''publicAccessPrefix''countryCode'This module exports the following functions when useed:
new(publicAccessPrefix,internationalPrefix,longDistancePrefix,countryCode,areaCode,pbxCode)
Section titled “new(publicAccessPrefix,internationalPrefix,longDistancePrefix,countryCode,areaCode,pbxCode)”The new operator returns an object of this type and sets its locational context according to the passed parameters. See
OpenSIPS::Utils::PhoneNumbers above.
canonicalForm( number [, context] )
Section titled “canonicalForm( number [, context] )”Convert a phone number (given as first argument) into its canonical form. When no context is passed in as the second argument, the default context from the systems configuration file is used.
dialNumber( number [, context] )
Section titled “dialNumber( number [, context] )”Convert a canonical phone number (given in the first argument) into a number to to dial. WHen no context is given in the second argument, a default context from the systems configuration is used.
OpenSIPS::LDAPUtils::LDAPConf
Section titled “OpenSIPS::LDAPUtils::LDAPConf”OpenSIPS::LDAPUtils::LDAPConf - Read openldap config from standard config files.
use OpenSIPS::LDAPUtils::LDAPConf;my $conf = new OpenSIPS::LDAPUtils::LDAPConf();This module may be used to retrieve the global LDAP configuration as
used by other LDAP software, such as nsswitch.ldap and pam-ldap. The configuration is
usualy stored in /etc/openldap/ldap.conf
When used from an account with sufficient privilegs (e.g. root), the ldap manager passwort is also retrieved.
Constructor new()
Section titled “Constructor new()”Returns a new, initialized OpenSIPS::LDAPUtils::LDAPConf
object.
Method base()
Section titled “Method base()”Returns the servers base-dn to use when doing queries.
Method host()
Section titled “Method host()”Returns the ldap host to contact.
Method port()
Section titled “Method port()”Returns the ldap servers port.
Method uri()
Section titled “Method uri()”Returns an uri to contact the ldap server. When there is no
ldap_uri in the configuration file, an ldap: uri is constucted from host
and port.
Method rootbindpw()
Section titled “Method rootbindpw()”Returns the ldap “root” password.
Note that the rootbindpw
is only available when the current account has sufficient privilegs
to access /etc/openldap/ldap.secret.
Method rootbinddn()
Section titled “Method rootbinddn()”Returns the DN to use for “root”-access to the ldap server.
Method binddn()
Section titled “Method binddn()”Returns the DN to use for authentication to the ldap server. When
no bind dn has been specified in the configuration file, returns
the rootbinddn.
Method bindpw()
Section titled “Method bindpw()”Returns the password to use for authentication to the ldap server.
When no bind password has been specified, returns the rootbindpw if any.
OpenSIPS::LDAPUtils::LDAPConnection
Section titled “OpenSIPS::LDAPUtils::LDAPConnection”OpenSIPS::LDAPUtils::LDAPConnection - Perl module to perform simple LDAP queries.
OO-Style interface:
use OpenSIPS::LDAPUtils::LDAPConnection;my $ldap = new OpenSIPS::LDAPUtils::LDAPConnection;my @rows = $ldap-search("uid=andi","ou=people,ou=coreworks,ou=de");Procedural interface:
use OpenSIPS::LDAPUtils::LDAPConnection;my @rows = $ldap->search( new OpenSIPS::LDAPUtils::LDAPConfig(), "uid=andi","ou=people,ou=coreworks,ou=de");This perl module offers a somewhat simplified interface to the
Net::LDAP functionality.
It is intended for cases where just a few attributes should be
retrieved without the overhead of the full featured Net::LDAP.
Constructor new( [config, [authenticated]] )
Section titled “Constructor new( [config, [authenticated]] )”Set up a new LDAP connection.
The first argument, when given, should be a hash reference pointing
to to the connection parameters, possibly an OpenSIPS::LDAPUtils::LDAPConfig
object. This argument may be undef in which case a new
(default) OpenSIPS::LDAPUtils::LDAPConfig
object is used.
When the optional second argument is a true value, the connection will be authenticated. Otherwise an anonymous bind is done.
On success, a new LDAPConnection object is
returned, otherwise the result is undef.
Function/Method search( conf, filter, base, [requested_attributes …])
Section titled “Function/Method search( conf, filter, base, [requested_attributes …])”perform an ldap search, return the dn of the first matching directory entry, unless a specific attribute has been requested, in wich case the values(s) fot this attribute are returned.
When the first argument (conf) is a OpenSIPS::LDAPUtils::LDAPConnection,
it will be used to perform the queries. You can pass the first
argument implicitly by using the “method” syntax.
Otherwise the conf
argument should be a reference to a hash containing the connection
setup parameters as contained in a OpenSIPS::LDAPUtils::LDAPConf
object. In this mode, the OpenSIPS::LDAPUtils::LDAPConnection
from previous queries will be reused.
Arguments:
Section titled “Arguments:”conf
configuration object, used to find host,port,suffix and use_ldap_checks
filter
ldap search filter, eg ‘(mail=some@domain)’
base
search base for this query. If undef use default suffix, concat base with default suffix if the last char is a ’,’
requested_attributes
retrieve the given attributes instead of the dn from the ldap directory.
Result:
Section titled “Result:”Without any specific requested_attributes, return
the dn of all matching entries in the LDAP directory.
When some requested_attributes are given,
return an array with those attibutes. When multiple entries match
the query, the attribute lists are concatenated.
OpenSIPS::VDB
Section titled “OpenSIPS::VDB”This package is an (abstract) base class for all virtual databases. Derived packages can be configured to be used by OpenSIPS as a database.
The base class itself should NOT be used in this context, as it does not provide any functionality.
OpenSIPS::Constants
Section titled “OpenSIPS::Constants”This package provides a number of constants taken from enums and defines of OpenSIPS header files. Unfortunately, there is no mechanism for updating the constants automatically, so check the values if you are in doubt.
OpenSIPS::VDB::Adapter::Speeddial
Section titled “OpenSIPS::VDB::Adapter::Speeddial”This adapter can be used with the speeddial module.
OpenSIPS::VDB::Adapter::Alias
Section titled “OpenSIPS::VDB::Adapter::Alias”This package is intended for usage with the alias_db module. The query VTab has to take two arguments and return an array of two arguments (user name/domain).
query(conds,retkeys,order)
Section titled “query(conds,retkeys,order)”Queries the vtab with the given arguments for request conditions, keys to return and sort order column name.
OpenSIPS::VDB::Adapter::AccountingSIPtrace
Section titled “OpenSIPS::VDB::Adapter::AccountingSIPtrace”This package is an Adapter for the acc and siptrace modules, featuring only an insert operation.
OpenSIPS::VDB::Adapter::Describe
Section titled “OpenSIPS::VDB::Adapter::Describe”This package is intended for debug usage. It will print information about requested functions and operations of a client module.
Use this module to request schema information when creating new adapters.
OpenSIPS::VDB::Adapter::Auth
Section titled “OpenSIPS::VDB::Adapter::Auth”This adapter is intended for usage with the auth_db module. The VTab should take a username as an argument and return a (plain text!) password.
OpenSIPS::VDB::ReqCond
Section titled “OpenSIPS::VDB::ReqCond”This package represents a request condition for database access, consisting of a column name, an operator (=, <, >, …), a data type and a value.
This package inherits from OpenSIPS::VDB::Pair and thus includes its methods.
new(key,op,type,name)
Section titled “new(key,op,type,name)”Constructs a new Column object.
Returns or sets the current operator.
OpenSIPS::VDB::Pair
Section titled “OpenSIPS::VDB::Pair”This package represents database key/value pairs, consisting of a key, a value type, and the value.
This package inherits from OpenSIPS::VDB::Value and thus has the same methods.
new(key,type,name)
Section titled “new(key,type,name)”Constructs a new Column object.
Returns or sets the current key.
OpenSIPS::VDB::VTab
Section titled “OpenSIPS::VDB::VTab”This package handles virtual tables and is used by the OpenSIPS::VDB class to store information about valid tables. The package is not inteded for end user access.
Constructs a new VTab objectcall(op,[args])
Section titled “call(op,[args])”Invokes an operation on the table (insert, update, …) with the given arguments.
OpenSIPS::VDB::Value
Section titled “OpenSIPS::VDB::Value”This package represents a database value. Additional to the data itself, information about its type is stored.
stringification
Section titled “stringification”When accessing a OpenSIPS::VDB::Value object as a string, it simply returns its data regardless of its type. =cut
use strict;
package OpenSIPS::VDB::Value;
use overload ’""’ => &stringify;
sub stringify { shift->{data} }
use OpenSIPS; use OpenSIPS::Constants;
our @ISA = qw ( OpenSIPS::Utils::Debug );
new(type,data)
Section titled “new(type,data)”Constructs a new Value object. Its data type and the data are passed as parameters.
type()
Section titled “type()”Returns or sets the current data type. Please consider using the constants from OpenSIPS::Constants
data()
Section titled “data()”Returns or sets the current data.
OpenSIPS::VDB::Column
Section titled “OpenSIPS::VDB::Column”This package represents database column definition, consisting of a column name and its data type.
Stringification
Section titled “Stringification”When accessing a OpenSIPS::VDB::Column object as a string, it simply returns its column name regardless of its type. =cut
package OpenSIPS::VDB::Column;
use overload ’""’ => &stringify;
sub stringify { shift->{name} }
use OpenSIPS; use OpenSIPS::Constants;
our @ISA = qw ( OpenSIPS::Utils::Debug );
new(type,name)
Section titled “new(type,name)”Constructs a new Column object. Its type and the name are passed as parameters.
type( )
Section titled “type( )”Returns or sets the current type. Please consider using the constants from OpenSIPS::Constants
name()
Section titled “name()”Returns or sets the current column name.
OpenSIPS::VDB::Result
Section titled “OpenSIPS::VDB::Result”This class represents a VDB result set. It contains a column definition, plus an array of rows. Rows themselves are simply references to arrays of scalars.
new(coldefs,[row, row, …])
Section titled “new(coldefs,[row, row, …])”The constructor creates a new Result object. Its first parameter is a reference to an array of OpenSIPS::VDB::Column objects. Additional parameters may be passed to provide initial rows, which are references to arrays of scalars.
coldefs()
Section titled “coldefs()”Returns or sets the column definition of the object.rows()
Section titled “rows()”Returns or sets the rows of the object.Perl samples
Section titled “Perl samples”sample directory
Section titled “sample directory”There are a number of example scripts in the “samples/”. They are documented well. Read them, it will explain a lot to you :)
If you want to use any of these scripts directly in your implementation, you can use Perl’s “require” mechanism to import them (just remember that you need to use quotes when require’ing .pl files).
Script descriptions
Section titled “Script descriptions”The included sample scripts are described below:
branches.pl
Section titled “branches.pl”The minimal function in branches.pl demonstrates that you can access the “append_branch” function from within perl, just as you would have done from your normal configuration file. You’ll find documentation on the concepts of branching in the OpenSIPS documentation.
firstline.pl
Section titled “firstline.pl”Message’s first_line structure may be evaluated. Message can be either of SIP_REQUEST or SIP_REPLY. Depending on that, different information can be received. This script demonstrates these functions.
flags.pl
Section titled “flags.pl”The perl module provides access to OpenSIPS’s flagging mechanism. The flag names available for OpenSIPS modules are made available through the OpenSIPS::Constants package, so you can flag messages as “green”, “magenta” etc.
The first function, setflag, demonstrates how the “green” flag is set. In the second function, readflag, the “green” and “magenta” flags are evaluated.
functions.pl
Section titled “functions.pl”This sample script demonstrates different things related to calling functions from within perl, and the different types of functions you can offer for OpenSIPS access.
“exportedfuncs” simply demonstrates that you can use the moduleFunction method to call functions offered by other modules. The results are equivalent to calling these functions from your config file. In the demonstrated case, telephone calls with a destination number beginning with 555… are rejected with an internal server error. Other destination addresses are passed to the alias_db module.
Please note that the moduleFunction method is not fully available in OpenSIPS 1.2. See the method’s documentation for details.
“paramfunc” shows that you can pass arbitrary strings to perl functions. Do with them whatever you want :)
“autotest” demonstrates that unknown functions in OpenSIPS::Message objects are automatically transformed into calls to module functions.
The “diefunc”s show that dying perl scripts - by “manual” dying, or because of script errors - are handled by the OpenSIPS package. The error message is logged through OpenSIPS’s logging mechanism. Please note that this only works correctly if you do NOT overwrite the default die handler. Oh, yes, that works for warnings, too.
headers.pl
Section titled “headers.pl”Header extraction is among the most crucial functionalities while processing SIP messages. This sample script demonstrates access to header names and values within two sample functions.
“headernames” extracts all header names and logs their names.
“someheaders” logs the contents of the two headers, “To” and “WWW-Contact”. As you can see, headers that occur more than once are retrieved as an array, which may be accessed by Perl’s array accessing methods.
logging.pl
Section titled “logging.pl”For debugging purposes, you probably want to write messages to the syslog. The “logdemo” shows three ways to access the OpenSIPS log function: it is available through the OpenSIPS class as well as through the OpenSIPS::Message class.
Remember that you can use exported functions from other modules. You may thus as well use the “xlog” module and it’s xlog function.
The L_INFO, L_DBG, L_ERR, L_CRIT… constants are available through the OpenSIPS::Constants package.
messagedump.pl
Section titled “messagedump.pl”This script demonstrates how to access the whole message header of the current message. Please note that modifications on the message made by earlier function calls in your configuration script may NOT be reflected in this dump.
persistence.pl
Section titled “persistence.pl”When processing SIP messages, you may want to use persistent data across multiple calls to your Perl functions. Your first option is to use global variables in your script. Unfortunately, these globals are not visible from the mulitple instances of OpenSIPS. You may want to use a mechanism such as the IPC::Shareable shared memory access package to correct this.
phonenumbers.pl
Section titled “phonenumbers.pl”The OpenSIPS::Utils::PhoneNumbers package provides two methods for the transformation of local to canonical telephone numbers, and vice versa. This script demonstrates it’s use.
pseudovars.pl
Section titled “pseudovars.pl”This script demonstrates the Perl module’s “pseudoVar” method. It may be used to retrieve the values of current pseudo variables.
You might notice that there is no particular function for setting pseudo variables; you may use the exported functions from the avpops module, though.
Frequently Asked Questions
Section titled “Frequently Asked Questions”Q: Are there known bugs in the Perl module?
The Perl module does have a few shortcomings that may be regarded as bugs.
Q: Where can I find more about OpenSIPS?
Take a look at http://www.opensips.org/.
Q: Where can I post a question about this module?
First at all check if your question was already answered on one of our mailing lists:
E-mails regarding any stable OpenSIPS release should be sent to users@lists.opensips.org and e-mails regarding development versions should be sent to devel@lists.opensips.org.
If you want to keep the mail private, send it to users@lists.opensips.org.
Q: How can I report a bug?
Please follow the guidelines provided at: https://github.com/OpenSIPS/opensips/issues.
Contributors
Section titled “Contributors”By Commit Statistics
Section titled “By Commit Statistics”Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
| # | Name | DevScore | Commits | Lines++ | Lines— |
|---|---|---|---|---|---|
| 1. | Bastian Friedrich | 102 | 38 | 6817 | 308 |
| 2. | Bogdan-Andrei Iancu (@bogdan-iancu) | 42 | 26 | 617 | 602 |
| 3. | Stefan Darius (@dariusstefan) | 23 | 4 | 1764 | 224 |
| 4. | Daniel-Constantin Mierla (@miconda) | 18 | 14 | 139 | 102 |
| 5. | Razvan Crainea (@razvancrainea) | 5 | 3 | 14 | 5 |
| 6. | Julien Blache | 4 | 1 | 80 | 64 |
| 7. | Ancuta Onofrei | 3 | 1 | 14 | 20 |
| 8. | Liviu Chircu (@liviuchircu) | 3 | 1 | 6 | 6 |
| 9. | Boris Ratner | 3 | 1 | 6 | 5 |
| 10. | Julián Moreno Patiño | 3 | 1 | 4 | 6 |
All remaining contributors: Klaus Darilion, Konstantin Bokarius, Ovidiu Sas (@ovidiusas), Edson Gellert Schubert, Dan Pascu (@danpascu).
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits
(3) ignoring whitespace edits, renamed files and auto-generated files
By Commit Activity
Section titled “By Commit Activity”| # | Name | Commit Activity |
|---|---|---|
| 1. | Stefan Darius (@dariusstefan) | Jun 2026 - Jul 2026 |
| 2. | Razvan Crainea (@razvancrainea) | Jun 2011 - Jun 2026 |
| 3. | Julián Moreno Patiño | Feb 2016 - Feb 2016 |
| 4. | Bogdan-Andrei Iancu (@bogdan-iancu) | Dec 2006 - Nov 2014 |
| 5. | Liviu Chircu (@liviuchircu) | Mar 2014 - Mar 2014 |
| 6. | Boris Ratner | Jan 2013 - Jan 2013 |
| 7. | Ovidiu Sas (@ovidiusas) | Oct 2010 - Oct 2010 |
| 8. | Dan Pascu (@danpascu) | Aug 2008 - Aug 2008 |
| 9. | Klaus Darilion | Jul 2008 - Jul 2008 |
| 10. | Daniel-Constantin Mierla (@miconda) | Dec 2006 - Mar 2008 |
All remaining contributors: Konstantin Bokarius, Edson Gellert Schubert, Bastian Friedrich, Ancuta Onofrei, Julien Blache.
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Bogdan-Andrei Iancu (@bogdan-iancu), Ovidiu Sas (@ovidiusas), Klaus Darilion, Daniel-Constantin Mierla (@miconda), Konstantin Bokarius, Edson Gellert Schubert, Bastian Friedrich.
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0