User Tools

Site Tools


devel:kamailio-5.0-design

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
devel:kamailio-5.0-design [2016/03/01 09:21]
miconda [Exporting Functions To Embedded Interpreters]
devel:kamailio-5.0-design [2016/03/01 09:49]
miconda [Routing Logic In Embedded Interpreters Scripting]
Line 39: Line 39:
   * pointer to c function   * pointer to c function
  
 +Example:
 +
 +<code c>
 +// export t_reply(200, "OK")
 +
 +sr_exapi_t mod_exapi[] = {
 +  { "sr.tm", "reply", {PARAM_INT, PARAM_STR, 0}, t_reply },
 +  { 0, 0, {0}, 0}
 +};
 +</code>
  
 ==== Routing Logic In Embedded Interpreters Scripting ==== ==== Routing Logic In Embedded Interpreters Scripting ====
Line 46: Line 56:
   * routing logic in an embedded language should allow reloading at runtime without kamailio restart   * routing logic in an embedded language should allow reloading at runtime without kamailio restart
  
 +=== Implementation Ideas ===
 +
 +
 +Example kamailio.cfg for native interpreter:
 +
 +<code>
 +# core parameters
 +...
 +
 +# load modules
 +...
 +
 +# modules parameters
 +...
 +
 +routing="native" # default
 +
 +request_route {
 +  ...
 +}
 +...
 +reply_route {
 +  ...
 +}
 +...
 +</code>
 +
 +Example kamailio.cfg for lua interpreter:
 +
 +<code>
 +# core parameters
 +...
 +
 +# load modules
 +...
 +
 +# modules parameters
 +...
 +
 +routing="lua" with "/path/to/script.lua"
 +
 +</code>
 +
 +The script /path/to/script.lua:
 +
 +<code>
 +function request_route()
 +  ...
 +  sr.t_on_branch("my_branch_route");
 +end
 +
 +function reply_route()
 +  ...
 +end
 +
 +function my_branch_route()
 +  ...
 +end
 +...
 +</code>
 +
 +Expected changes:
 +  * each module that offers an interpreter for config will advertise a special structure with functions to be executed on various events (e.g., request received, reply received, etc...)
 +  * keep the name of routing blocks for failure/branch/branch-failure processing inside tm (along with existing index of the routing block for "native" config case)
 +  * define the function names for routing blocks that are executed automatically
 +    * such as:
 +      * request_route
 +      * reply_route
 +      * onsend_route
 +      * various event_route blocks (e.g., htable:init)
 +    * eventually there can be a mapping of names used inside kamailio native config and functions inside the embedded interpreter that is inside each module, so each can have a naming pattern more suitable/friendly for its language (e.g., one may prefer request_route(), other requestRoute() and another RequestRoute())
 +    * for event routes executed automatically (not the one armed for tm branch failure which sets the name at runtime), the pattern can be:
 +      * modname_event_route(eventname) -- for example:
 +
 +<code>
 +// event_route[htable:init] 
 +function htable_event_route(evname)
 +  if evname=="init" then
 +     ...
 +  else
 +     ...
 +  end
 +</code>
 ===== Source Tree Structure ===== ===== Source Tree Structure =====
  
devel/kamailio-5.0-design.txt ยท Last modified: 2016/05/03 18:33 by miconda