Table of Contents
List of Examples
load
parametersqlang_dofile
usagesqlang_dostring
usagesqlang_run
usagesqlang_runstring
usageTable of Contents
This module allows executing Squirrel Language (SQLang) scripts from config file. It exports all KEMI functions to SQLang in order to access the current processed SIP message. These functions are within SQLang object 'KSR' (a table object).
It includes the Squirrel Language engine (http://www.squirrel-lang.org). Exported API from SIP router to SQLang is documented in the dokuwiki.
The module has two SQLang contexts:
first is used for functions sqlang_dofile() and sqlang_dostring().
second is used for function sqlan_run() and parameter 'load'. Therefore sqlang_run() cannot execute functions from scripts loaded via sqlang_dofile() in config. This is kind of caching mode, avoiding reading file every time, but you must be sure you do not have something that is executed by default and requires access to SIP message. This environment is also used by KEMI framework for the config SIP routing functions.
Set the path to the SQLang file to be loaded at startup. Then you can use sqlang_run(function, params) to execute a function from the script at runtime. If you use it for KEMI configuration, then it has to include the required functions.
Default value is “null”.
Example 1.1. Set load
parameter
... modparam("app_sqlang", "load", "/usr/local/etc/kamailio/sqlang/myscript.sq") ...
Note: not implemented yet.
Execute the SQLang script stored in 'path'. The parameter can be a string with pseudo-variables evaluated at runtime.
Example 1.2. sqlang_dofile
usage
... sqlang_dofile("/usr/local/etc/kamailio/sqlang/myscript.sq"); ...
Note: not implemented yet.
Execute the Squirrel script stored in parameter. The parameter can be a string with pseudo-variables.
Example 1.3. sqlang_dostring
usage
... if(!sqlang_dostring('KSR.dbg("test message\n")')) { xdbg("SCRIPT: failed to execute squirrel script!\n"); } ...
Execute the Squirrel function 'func' giving params as parameters. There can be up to 3 string parameters. The function must exist in the script loaded at startup via parameter 'load'. Parameters can be strings with pseudo-variables that are evaluated at runtime.
Example 1.4. sqlang_run
usage
... if(!sqlang_run("sqlang_append_fu_to_reply")) { xdbg("SCRIPT: failed to execute squirrel function!\n"); } ... sqlang_run("sqlang_funcx", "$rU", "2"); ...
Note: not implemented yet.
Execute the SQLang script stored in parameter. The parameter can be a string with pseudo-variables. The script is executed in JS context specific to loaded JS files at startup.
Example 1.5. sqlang_runstring
usage
... if(!sqlang_runstring('KSR.dbg("Hello World from $fU\n")')) { xdbg("failed to execute squirrel script!\n"); } ...
Marks the need to reload the SQLang script pointed by 'load' parameter. The actual reload is done by every working process when the next call to sqlang_run() function or KEMI config is executed.
Name: app_sqlang.reload
Parameters: none
Example:
... kamcmd app_sqlang.reload ...
Create your SQLang script and stored on file system, say: '/usr/local/etc/kamailio/sqlang/myscript.sq'.
... function sr_append_fu_to_reply() { KSR.hdr.append_to_reply("P-From: " + KSR.pv.get("$fu") + "\r\n"); } ...
Load the script via parameter 'load' and execute function via sqlang_run(...).
... modparam("app_sqlang", "load", "/usr/local/etc/kamailio/sqlang/myscript.sq") ... request_route { ... if(!sqlang_run("sr_append_fu_to_reply")) { xdbg("SCRIPT: failed to execute squirrel function!\n"); } ... } ...