LUA 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 Lua module, you can easily implement your own OpenSIPS extensions in Lua.
Installing the module
Section titled “Installing the module”This Lua module is loaded in opensips.cfg (just like all the other modules) with loadmodule(“/path/to/lua.so”);.
For the Lua module to compile, you need a recent version of Lua (tested with 5.1) linked dynamically. The default version of your favorite Linux distribution should work fine.
Using the module
Section titled “Using the module”With the Lua module, you can access to lua function on the OpenSIPS side. You need to define a file to load and call a function from it. Write a function “mongo_alias” and then write in your opensips.cfg
...if (lua_exec("mongo_alias")) { ...}...On the Lua side, you have access to opensips functions and variables (AVP, pseudoVar, …). Read the documentation below for further informations.
Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”None ;-)
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:
- Lua 5.1.x or later
- memcached
This module has been developed and tested with Lua 5.1.?, but should work with any 5.1.x release. Earlier versions do not work.
On current Debian systems, at least the following packages should be installed:
- lua5.1
- liblua5.1-0-dev
- libmemcached-dev
- libmysqlclient-dev
It was reported that other Debian-style distributions (such as Ubuntu) need the same packages.
On OpenBSD systems, at least the following packages should be installed:
- Lua
Exported Parameters
Section titled “Exported Parameters”luafilename (string)
Section titled “luafilename (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 Lua module as necessary.
The default value is “/etc/opensips/opensips.lua”
...modparam("lua", "luafilename", "/etc/opensips/opensips.lua")...lua_auto_reload (int)
Section titled “lua_auto_reload (int)”Define this value to 1 if you want to reload automatically the lua script. Disabled by default.
warn_missing_free_fixup (int)
Section titled “warn_missing_free_fixup (int)”When you call a function via moduleFunc() you could have a memleak. Enable this warns you when you’re doing it. Enabled by default.
lua_allocator (string)
Section titled “lua_allocator (string)”Change the default memory allocator for the lua module. Possible values are :
- opensips (default)
- malloc
Exported Functions
Section titled “Exported Functions”lua_exec(func, [param])
Section titled “lua_exec(func, [param])”Calls a Lua function with passing it the current SIP message. This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE and BRANCH_ROUTE.
Parameters:
- func (string) - Lua function name
- param (string, optional) - Parameter to be passed to the Lua function.
...if (lua_exec("mongo_alias")) { ...}...lua_meminfo()
Section titled “lua_meminfo()”Logs informations about memory.
Exported MI Functions
Section titled “Exported MI Functions”Name: watch
Parameters: none
- action (optional) - ‘add’ or ‘delete’
- extension (optional) - required if action is provided
MI FIFO Command Format:
$ opensips-cli -x mi watchOpenSIPS Lua API
Section titled “OpenSIPS Lua API”Available functions
Section titled “Available functions”This module provides access to a limited number of OpenSIPS core functions.
xdbg(message)
Section titled “xdbg(message)”An alias for xlog(DBG, message)
xlog([level],message)
Section titled “xlog([level],message)”Logs the message with OpenSIPS’s logging facility. The logging level is one of the following:
- ALERT
- CRIT
- ERR
- WARN
- NOTICE
- INFO
- DBG
WarnMissingFreeFixup
Section titled “WarnMissingFreeFixup”Dynamically change the variable warn_missing_free_fixup.
getpid
Section titled “getpid”Returns the current pid.
getmem
Section titled “getmem”Returns a table with the size of allocated memory and the fragmentation.
getmeminfo
Section titled “getmeminfo”Returns a table with memory infos.
gethostname
Section titled “gethostname”Returns the value of the current hostname.
getType(msg)
Section titled “getType(msg)”Returns “SIP_REQUEST” or “SIP_REPLY”.
isMyself(host, port)
Section titled “isMyself(host, port)”Test if the host and optionally the port represent one of the addresses that OpenSIPS listens on.
grepSockInfo(host, port)
Section titled “grepSockInfo(host, port)”Similar to isMyself(), but without taking a look into the aliases.
getURI_User(msg)
Section titled “getURI_User(msg)”Returns the user of the To URI.
getExpires(msg)
Section titled “getExpires(msg)”Returns the expires header of the current message.
getHeader(msg, header)
Section titled “getHeader(msg, header)”Returns the value of the specified header.
getContact(msg)
Section titled “getContact(msg)”Returns a table with the contact header.
getRoute(msg)
Section titled “getRoute(msg)”Returns a table with the Route header.
moduleFunc(msg, function, args1, args2, …)
Section titled “moduleFunc(msg, function, args1, args2, …)”You can pass arguments to this function.
getStatus(msg)
Section titled “getStatus(msg)”Returns the current status if the SIP message is a SIP_REPLY.
getMethod(msg)
Section titled “getMethod(msg)”Returns the current method.
getSrcIp(msg)
Section titled “getSrcIp(msg)”Returns the IP address of the source.
getDstIp(msg)
Section titled “getDstIp(msg)”Returns the IP address of the destination.
AVP_get(name)
Section titled “AVP_get(name)”Returns an AVP variable.
AVP_set(name, value)
Section titled “AVP_set(name, value)”Defines an AVP variable.
AVP_destroy(name)
Section titled “AVP_destroy(name)”Destroys an AVP variable.
pseudoVar(msg, variable)
Section titled “pseudoVar(msg, variable)”Returns a pseudoVar.
pseudoVarSet(msg, variable, value)
Section titled “pseudoVarSet(msg, variable, value)”Sets the value of a pseudoVar.
scriptVarGet(variable)
Section titled “scriptVarGet(variable)”Returns a script variable.
scriptVarSet(variable, value)
Section titled “scriptVarSet(variable, value)”Sets the value of a script variable.
add_lump_rpl(msg, header)
Section titled “add_lump_rpl(msg, header)”Add header to the reply.
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. | Arnaud Chong + Eric Gouyer | 38 | 1 | 4335 | 0 |
| 2. | Razvan Crainea (@razvancrainea) | 33 | 26 | 272 | 228 |
| 3. | Vlad Patrascu (@rvlad-patrascu) | 24 | 16 | 326 | 280 |
| 4. | Liviu Chircu (@liviuchircu) | 13 | 10 | 23 | 71 |
| 5. | Stefan Darius (@dariusstefan) | 10 | 5 | 434 | 35 |
| 6. | Bogdan-Andrei Iancu (@bogdan-iancu) | 8 | 6 | 9 | 3 |
| 7. | Vlad Paiu (@vladpaiu) | 5 | 3 | 7 | 9 |
| 8. | Maksym Sobolyev (@sobomax) | 3 | 1 | 6 | 3 |
| 9. | Peter Lemenkov (@lemenkov) | 3 | 1 | 1 | 1 |
| 10. | Julián Moreno Patiño | 3 | 1 | 1 | 1 |
(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) | Feb 2012 - Jun 2026 |
| 3. | Vlad Patrascu (@rvlad-patrascu) | May 2017 - Jun 2023 |
| 4. | Maksym Sobolyev (@sobomax) | Feb 2023 - Feb 2023 |
| 5. | Bogdan-Andrei Iancu (@bogdan-iancu) | May 2014 - Jan 2020 |
| 6. | Liviu Chircu (@liviuchircu) | Mar 2014 - Mar 2019 |
| 7. | Peter Lemenkov (@lemenkov) | Jun 2018 - Jun 2018 |
| 8. | Julián Moreno Patiño | Feb 2016 - Feb 2016 |
| 9. | Vlad Paiu (@vladpaiu) | Feb 2012 - Jun 2012 |
| 10. | Arnaud Chong + Eric Gouyer | Dec 2011 - Dec 2011 |
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Vlad Patrascu (@rvlad-patrascu), Peter Lemenkov (@lemenkov), Liviu Chircu (@liviuchircu), Vlad Paiu (@vladpaiu), Arnaud Chong + Eric Gouyer.
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0