Initial author: Daniel-Constantin Mierla
Module app_lua allows execution of Lua scripts from SIP router configuration file, providing access to SIP message which is processed at that time. Exported functions by app_lua are available in the Lua script as package sr.
References:
Remarks:
Core functions.
Print message to L_DBG level using internal log API.
Prototype
sr.dbg("message")
Print message to L_ERR level using internal log API.
Prototype
sr.err("message")
Print message to 'level' using internal log API.
Prototype
sr.log("level", "message")
Parameter level can be“
Run a function exported by a module
Prototype:
sr.modf("function", "param1", "param2", ...);
Can be up to 6 optional parameters.
Example:
sr.modf("sl_reply_error");
Note that module functions that have parameter fixups cannot be executed unless they have free fixup. This is to prevent memory leaks caused by fixup functions. If you have doubts about a module function, whether it is safe to execute or not from Lua, ask on devel mailing list: sr-dev [at] lists.sip-router.org.
Return true if the URI matches local IPs and aliases.
Prototype
sr.is_myself("uri")
Set message flag.
Prototype
sr.setflag(index)
Reset message flag.
Prototype
sr.resetflag(index)
Test if message flag is set.
Prototype
sr.isflagset(index)
Set branch flag.
Prototype
sr.setbflag(index)
Reset branch flag.
Prototype
sr.resetflag(index)
Test if branch flag is set.
Prototype
sr.isbflagset(index)
Set request URI.
Prototype
sr.seturi("uri")
Set request URI user part.
Prototype
sr.setuser("user")
Set request URI host part.
Prototype
sr.sethost("host")
Set destination URI (outbound proxy).
Prototype
sr.setdsturi("uri")
Reset destination URI (outbound proxy).
Prototype
sr.resetdsturi()
Header management functions.
Append header to end of headers list.
Prototype
sr.hdr.append("text")
Insert header to first position.
Prototype
sr.hdr.insert("text")
Append a header to SIP reply generated by proxy.
Prototype
sr.hdr.append_to_reply("text")
Pseudo-variable management functions.
Get the value of a pseudo-variable.
Prototype
sr.pv.get("pv")
Set the integer value to pseudo-variable.
Prototype
sr.pv.seti("pv", value)
Set the string value to pseudo-variable.
Prototype
sr.pv.sets("pv", "value")
Unset pseudo-variables (assign $null).
Prototype
sr.pv.unset("pv")
Check if the pseudo-variable value is $null or not.
Prototype
sr.pv.is_null("pv")
Functions of SL module.
Send SIP reply.
Prototype
sr.sl.send_reply(code, "reason")
Example:
lua_dostring("sr.sl.send_reply(200, [[ok from lua]])");
Return To-dag for SIP reply.
Prototype
sr.sl.get_reply_totag()
Send stateful SIP reply.
Prototype
sr.tm.t_reply(code, "reason")
Forward statefully SIP request.
Prototype
sr.tm.t_relay()
Set on branch route.
Prototype
sr.tm.t_on_branch("routeid")
Set on reply route.
Prototype
sr.tm.t_on_reply("routeid")
Set on failure route.
Prototype
sr.tm.t_on_failure("routeid")
Check for existence of transaction.
Prototype
sr.tm.t_check_trans()
Return >0 if the INVITE transaction is canceled.
Prototype
sr.tm.t_is_canceled()
Execute SQL query.
Prototype
sr.sqlops.query("connection", "query", "result")
Return a value from result of SQL query.
Prototype
sr.sqlops.value("result", row, column)
Return true if a value from result is NULL.
Prototype
sr.sqlops.is_null("result", row, column)
Return a column name from result of SQL query.
Prototype
sr.sqlops.column("result", index)
Return number of rows from result of SQL query.
Prototype
sr.sqlops.nrows("result")
Return number of columns from result of SQL query.
Prototype
sr.sqlops.ncols("result")
Free the result of SQL query.
Prototype
sr.sqlops.reset("result")
Add Record-Route header.
Prototype
sr.rr.record_route(["params"])
Handle Route headers.
Prototype
sr.rr.loose_route()
Send WWW digest authentication challenge reply (401).
Prototype
sr.auth.www_challenge("realm", flags)
Send Proxy digest authentication challenge reply (401).
Prototype
sr.auth.proxy_challenge("realm", flags)
Perform WWW digest authentication using password from parameter.
Prototype
sr.auth.pv_www_authenticate("realm", "password", flags)
Perform Proxy digest authentication using password from parameter.
Prototype
sr.auth.pv_proxy_authenticate("realm", "password", flags)
Delete authentication credentials from SIP request.
Prototype
sr.auth.consume_credentials()
Perform WWW digest authentication against database.
Prototype
sr.auth_db.www_authenticate("realm", "table")
Perform Proxy digest authentication against database.
Prototype
sr.auth_db.proxy_authenticate("realm", "table")
Handle Max Forward header.
Prototype
sr.maxfwd.process_maxfwd(newlimit)
Save contacts to user location table.
Prototype
sr.registrar.save("table" [, flags])
Lookup contacts in user location table.
Prototype
sr.registrar.lookup("table")
Select first destination address.
Prototype
sr.dispatcher...
Select next destination address.
Prototype
sr.dispatcher...
Set status for destination address.
Prototype
sr.dispatcher...
Detects if the message comes from a dispatcher address.
Prototype
sr.dispatcher...
Send an HTTP reply.
Prototype
sr.xhttp.reply(code, reason, content-type, body)