Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
api:lua:devel [2010/01/26 12:20] miconda |
api:lua:devel [2011/02/03 09:47] (current) 85.178.84.141 |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Lua API ====== | ====== Lua API ====== | ||
- | * load app_lua module | + | ===== Overview ===== |
- | * Lua: http:// | + | |
+ | <code c> | ||
+ | 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: | ||
+ | |||
+ | * **app_lua** module: [[http:// | ||
+ | * **Lua**: http:// | ||
+ | |||
+ | Remarks: | ||
+ | |||
+ | * check the modules' | ||
+ | * the parameters must be strings if the prototype have them in between double quotes, or integers if there are no double quotes | ||
+ | * any parameter specified in prototype enclosed in between square brackets is optional | ||
+ | |||
===== SR Package ===== | ===== SR Package ===== | ||
+ | |||
+ | Core functions. | ||
==== sr.dbg ==== | ==== sr.dbg ==== | ||
+ | |||
+ | Print message to L_DBG level using internal log API. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.dbg(" | ||
+ | </ | ||
==== sr.err ==== | ==== sr.err ==== | ||
+ | |||
+ | Print message to L_ERR level using internal log API. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.err(" | ||
+ | </ | ||
==== sr.log ==== | ==== sr.log ==== | ||
+ | |||
+ | Print message to ' | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.log(" | ||
+ | </ | ||
+ | |||
+ | Parameter level can be" | ||
+ | |||
+ | * dbg | ||
+ | * info | ||
+ | * warn | ||
+ | * err | ||
+ | * crit | ||
+ | |||
+ | ==== sr.modf ==== | ||
+ | |||
+ | Run a function exported by a module | ||
+ | |||
+ | Prototype: | ||
+ | |||
+ | <code c> | ||
+ | sr.modf(" | ||
+ | </ | ||
+ | |||
+ | Can be up to 6 optional parameters. | ||
+ | |||
+ | Example: | ||
+ | |||
+ | <code c> | ||
+ | sr.modf(" | ||
+ | </ | ||
+ | |||
+ | 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**. | ||
+ | |||
+ | ==== sr.is_myself ==== | ||
+ | |||
+ | Return true if the URI matches local IPs and aliases. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.is_myself(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== sr.setflag ==== | ||
+ | |||
+ | Set message flag. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.setflag(index) | ||
+ | </ | ||
+ | |||
+ | ==== sr.resetflag ==== | ||
+ | |||
+ | Reset message flag. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.resetflag(index) | ||
+ | </ | ||
+ | |||
+ | ==== sr.isflagser ==== | ||
+ | |||
+ | Test if message flag is set. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.isflagset(index) | ||
+ | </ | ||
+ | |||
+ | ==== sr.sebtflag ==== | ||
+ | |||
+ | Set branch flag. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.setbflag(index) | ||
+ | </ | ||
+ | |||
+ | ==== sr.resetflag ==== | ||
+ | |||
+ | Reset branch flag. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.resetflag(index) | ||
+ | </ | ||
+ | |||
+ | ==== sr.isbflagser ==== | ||
+ | |||
+ | Test if branch flag is set. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.isbflagset(index) | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== sr.seturi ==== | ||
+ | |||
+ | Set request URI. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.seturi(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.setuser ==== | ||
+ | |||
+ | Set request URI user part. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.setuser(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sethost ==== | ||
+ | |||
+ | Set request URI host part. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sethost(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.setdsturi ==== | ||
+ | |||
+ | Set destination URI (outbound proxy). | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.setdsturi(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.resetdsturi ==== | ||
+ | |||
+ | Reset destination URI (outbound proxy). | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.resetdsturi() | ||
+ | </ | ||
===== SR.HDR Package ===== | ===== SR.HDR Package ===== | ||
+ | |||
+ | Header management functions. | ||
==== sr.hdr.append ==== | ==== sr.hdr.append ==== | ||
+ | |||
+ | Append header to end of headers list. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.hdr.append(" | ||
+ | </ | ||
+ | |||
==== sr.hdr.insert ==== | ==== sr.hdr.insert ==== | ||
+ | |||
+ | Insert header to first position. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.hdr.insert(" | ||
+ | </ | ||
==== sr.hdr.remove ==== | ==== sr.hdr.remove ==== | ||
+ | |||
+ | Remove header. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.hdr.remove(" | ||
+ | </ | ||
==== sr.hdr.append_to_reply ==== | ==== sr.hdr.append_to_reply ==== | ||
+ | |||
+ | Append a header to SIP reply generated by proxy. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.hdr.append_to_reply(" | ||
+ | </ | ||
===== SR.PV Package ===== | ===== SR.PV Package ===== | ||
+ | |||
+ | Pseudo-variable management functions. | ||
==== sr.pv.get ==== | ==== sr.pv.get ==== | ||
+ | |||
+ | Get the value of a pseudo-variable. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.pv.get(" | ||
+ | </ | ||
==== sr.pv.seti ==== | ==== sr.pv.seti ==== | ||
+ | |||
+ | Set the integer value to pseudo-variable. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.pv.seti(" | ||
+ | </ | ||
==== sr.pv.sets ==== | ==== sr.pv.sets ==== | ||
- | ==== sr.pv.unet ==== | + | Set the string value to pseudo-variable. |
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.pv.sets(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.pv.unset ==== | ||
+ | |||
+ | Unset pseudo-variables (assign $null). | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.pv.unset(" | ||
+ | </ | ||
==== sr.pv.is_null ==== | ==== sr.pv.is_null ==== | ||
+ | Check if the pseudo-variable value is $null or not. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.pv.is_null(" | ||
+ | </ | ||
+ | |||
+ | ===== SR.SL Package ===== | ||
+ | |||
+ | Functions of SL module. | ||
+ | |||
+ | ==== sr.sl.send_reply ==== | ||
+ | |||
+ | Send SIP reply. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sl.send_reply(code, | ||
+ | </ | ||
+ | |||
+ | Example: | ||
+ | <code c> | ||
+ | lua_dostring(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sl.get_reply_totag ==== | ||
+ | |||
+ | Return To-dag for SIP reply. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sl.get_reply_totag() | ||
+ | </ | ||
+ | |||
+ | ===== SR.TM Package ===== | ||
+ | |||
+ | |||
+ | ==== sr.tm.t_reply ==== | ||
+ | |||
+ | Send stateful SIP reply. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_reply(code, | ||
+ | </ | ||
+ | |||
+ | ==== sr.tm.t_relay ==== | ||
+ | |||
+ | Forward statefully SIP request. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_relay() | ||
+ | </ | ||
+ | |||
+ | ==== sr.tm.t_on_branch ==== | ||
+ | |||
+ | Set on branch route. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_on_branch(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.tm.t_on_reply ==== | ||
+ | |||
+ | Set on reply route. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_on_reply(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.tm.t_on_failure ==== | ||
+ | |||
+ | Set on failure route. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_on_failure(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.tm.t_check_trans ==== | ||
+ | |||
+ | Check for existence of transaction. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_check_trans() | ||
+ | </ | ||
+ | |||
+ | ==== sr.tm.t_is_canceled ==== | ||
+ | |||
+ | Return >0 if the INVITE transaction is canceled. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.tm.t_is_canceled() | ||
+ | </ | ||
+ | |||
+ | ===== SR.SQLOPS Package ===== | ||
+ | |||
+ | ==== sr.sqlops.query ==== | ||
+ | |||
+ | Execute SQL query. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.query(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sqlops.value ==== | ||
+ | |||
+ | Return a value from result of SQL query. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.value(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== sr.sqlops.is_null ==== | ||
+ | |||
+ | Return true if a value from result is NULL. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.is_null(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sqlops.column ==== | ||
+ | |||
+ | Return a column name from result of SQL query. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.column(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sqlops.nrows ==== | ||
+ | |||
+ | Return number of rows from result of SQL query. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.nrows(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sqlops.ncols ==== | ||
+ | |||
+ | |||
+ | Return number of columns from result of SQL query. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.ncols(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.sqlops.reset ==== | ||
+ | |||
+ | |||
+ | Free the result of SQL query. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.sqlops.reset(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== SR.RR Package ===== | ||
+ | |||
+ | ==== sr.rr.record_route ==== | ||
+ | |||
+ | Add Record-Route header. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.rr.record_route([" | ||
+ | </ | ||
+ | |||
+ | ==== sr.rr.loose_route ==== | ||
+ | |||
+ | |||
+ | Handle Route headers. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.rr.loose_route() | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== SR.AUTH Package ===== | ||
+ | |||
+ | ==== sr.auth.www_challenge ==== | ||
+ | |||
+ | Send WWW digest authentication challenge reply (401). | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth.www_challenge(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.auth.proxy_challenge ==== | ||
+ | |||
+ | Send Proxy digest authentication challenge reply (401). | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth.proxy_challenge(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.auth.pv_www_authenticate ==== | ||
+ | |||
+ | Perform WWW digest authentication using password from parameter. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth.pv_www_authenticate(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== sr.auth.pv_proxy_authenticate ==== | ||
+ | |||
+ | |||
+ | Perform Proxy digest authentication using password from parameter. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth.pv_proxy_authenticate(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.auth.consume_credentials ==== | ||
+ | |||
+ | Delete authentication credentials from SIP request. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth.consume_credentials() | ||
+ | </ | ||
+ | |||
+ | ===== SR.AUTH_DB Package ===== | ||
+ | |||
+ | ==== sr.auth_db.www_authenticate ==== | ||
+ | |||
+ | Perform WWW digest authentication against database. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth_db.www_authenticate(" | ||
+ | </ | ||
+ | |||
+ | ==== sr.auth_db.proxy_authenticate ==== | ||
+ | |||
+ | Perform Proxy digest authentication against database. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.auth_db.proxy_authenticate(" | ||
+ | </ | ||
+ | |||
+ | ===== SR.MAXFWD Package ===== | ||
+ | |||
+ | ==== sr.maxfwd.process_maxfwd ==== | ||
+ | |||
+ | |||
+ | Handle Max Forward header. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.maxfwd.process_maxfwd(newlimit) | ||
+ | </ | ||
+ | |||
+ | ===== SR.REGISTRAR Package ===== | ||
+ | |||
+ | ==== sr.registrar.save ==== | ||
+ | |||
+ | Save contacts to user location table. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.registrar.save(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== sr.registrar.lookup ==== | ||
+ | |||
+ | Lookup contacts in user location table. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.registrar.lookup(" | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== SR.dispatcher Package ===== | ||
+ | |||
+ | ==== sr.dispatcher.select ==== | ||
+ | |||
+ | Select first destination address. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.dispatcher... | ||
+ | </ | ||
+ | |||
+ | ==== sr.dispatcher.next ==== | ||
+ | |||
+ | Select next destination address. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.dispatcher... | ||
+ | </ | ||
+ | |||
+ | ==== sr.dispatcher.mark ==== | ||
+ | |||
+ | Set status for destination address. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.dispatcher... | ||
+ | </ | ||
+ | |||
+ | ==== sr.dispatcher.is_from ==== | ||
+ | |||
+ | Detects if the message comes from a dispatcher address. | ||
+ | |||
+ | Prototype | ||
+ | |||
+ | <code c> | ||
+ | sr.dispatcher... | ||
+ | </ | ||
+ | |||
+ | ===== SR.XHTTP Package ===== | ||
+ | |||
+ | ==== sr.xhttp.reply ==== | ||
+ | |||
+ | Send an HTTP reply. | ||
+ | |||
+ | Prototype | ||
+ | <code c> | ||
+ | sr.xhttp.reply(code, | ||
+ | </ |