Copyright © 2007-2008 Voice Sistem SRL
Revision History | |
---|---|
Revision $Revision: 5895 $ | $Date: 2013-01-29 13:35:11 +0100 (Tue, 29 Jan 2013) $ |
Table of Contents
db_url
(string)table_name
(string)dpid_col
(string)pr_col
(string)match_op_col
(string)match_exp_col
(string)match_flags_col
(string)subst_exp_col
(string)repl_exp_col
(string)attrs_col
(string)disabled_col
(integer)attrs_pvar
(string)List of Examples
db_url
parametertable_name
parameterdpid_col
parameterpr_col
parametermatch_op_col
parametermatch_exp_col
parametermatch_flags_col
parametersubs_exp_col
parameterrepl_exp_col
parameterattrs_col
parameterdisabled_col
parameterattrs_pvar
parameterdp_translate
usagedp_translate
usagedp_translate
usageThis module implements generic string translations based on matching and replacement rules. It can be used to manipulate R-URI or a PV and to translated to a new format/value.
At startup, the module will load a set of transformation rules from a database. Every database raw will be stored in memory as a translation rule. Each rule will describe how the matching should be made, how the input value should be modified and which attributes should be set for the matching transformation.
The module expects an input value which will be matched against a rules via regexp or string matching. Overlapping matching expressions can be controlled via priorities. Once a rule is matched, the defined transformation (if any) is applied and the result is returned as output value. Also, if any string attribute is associated to the rule, this will be returned to the script along with the output value.
The first matching rule will be processed.
The module can be used to implement dialplans - do to auto completion of the dial numbers (like national to international), to convert generic numbers to specific numbers (like for emergency numbers).
Also the module can be used for detecting range or sets of numbers mapped on a service/case - attributes string can be used here to store extra information about the service/case.
Non-SIP string translation can be implemented - like converting country names from all possible formats to a canonical format: (UK, England, United Kingdom) -> GB.
Any other string-base translation or detection for whatever other purposes.
Depending what kind of operation (translation, matching, etc) you want to do with the module, you need to appropriate populate the DB records.
The definition of the tables used by the dialplan module can be found at http://www.opensips.org/html/docs/db/db-schema-devel.html#AEN1501
Recognize a number block in all forms (international, national) and convert it to a canonical format (e.164)
match_op = 1 (regexp)
match_exp = "^(0040|\+40|0|40)21[0-9]+" ; regular expresion that will be used to match with this rule (if the rule should be applied for the input string)
match_flags = 0 (0 - case sensitive, 1 - case insensitive matching)
subst_exp = "^(0040|\+40|0|40)(.+)" ; regular expresion used to do the transformation (first part of the subst operation)
repl_exp = "40\2" ; second part of the subst (output) - linked to the subst_exp field; when both defined, they work as a subst()
Recognize the name of a country (multiple languages) and convert it to a single fix value
match_op = 1 (regexp)
match_exp = "^((Germany)|(Germania)|(Deutschland)|(DE))" ; regular expresion that will be used to match with this rule (if the rule should be applied for the input string)
match_flags = 0 (0 - case sensitive, 1 - case insensitive matching)
subst_exp = NULL ; when translation is actually a replacement, this field must be NULL.
repl_exp = "DE" ; static string to replace the input - whenever this rule will match, it will return this string as output.
Recognize a block of numbers as belong to a single service and signalize this via an attribute.
match_op = 1 (regexp)
match_exp = "^021456[0-9]{5}" ; regular expresion that will be used to match with this rule (if the rule should be applied for the input string)
match_flags = 0 (0 - case sensitive, 1 - case insensitive matching)
subst_exp = NULL ; no translation
repl_exp = NULL ; no translation
attrs = "serviceX" ; whatever string you will get into OpenSIPS script and it will provide you more information (totally custom)
Recognize a fix string/number and replace it with something fix.
match_op = 0 (equal)
match_exp = "SIP server" ; string to be matched
match_flags = 0 (0 - case sensitive, 1 - case insensitive matching)
subst_exp = NULL ; no subst translation
repl_exp = "OpenSIPS" ; output string
The following libraries or applications must be installed before running OpenSIPS with this module loaded:
libpcre-dev - the development libraries of PCRE.
The translation rules will be loaded using this database url.
Default value is “mysql://opensips:opensipsrw@localhost/opensips”.
Example 1.1. Set db_url
parameter
... modparam("dialplan", "db_url", "mysql://user:passwb@localhost/db") ...
The table's name from which to load the translation rules.
Default value is “dialplan”.
The column name to store the dialplan ID group.
Default value is “dpid”.
The column name to store the priority of the corresponding rule from the database raw.
Default value is “pr”.
The column name to store the type of matching of the rule.
Default value is “match_op”.
The column name to store the rule match expression.
Default value is “match_exp”.
Example 1.6. Set match_exp_col
parameter
... modparam("dialplan", "match_exp_col", "column_name") ...
The column name to store various matching flags. Currently 0 - case sensitive matching, 1 - case insensitive matching.
Default value is “match_flags”.
Example 1.7. Set match_flags_col
parameter
... modparam("dialplan", "match_flags_col", "column_name") ...
The column name to store the rule's substitution expression.
Default value is “subst_exp”.
Example 1.8. Set subs_exp_col
parameter
... modparam("dialplan", "subst_exp_col", "column_name") ...
The column name to store the rule's replacement expression.
Default value is “repl_exp”.
The column name to store the rule's attributes to be set to the message.
Default value is “attrs”.
Will try to translate the src string into dest string according to the translation rules with dialplan ID equal to id.
Meaning of the parameters is as follows:
id - the dialplan id of possible matching rules. The id parameter can have the following types:
integer - the dialplan id is statically assigned
pvar - the dialplan id is the value of an existing pseudo-variable (as integer value)
table - Specifies the table where the search will take place. This parameter can be ommited. The default table is dialplan. The table parameter can have the following types:
string - the table name is statically assigned
src/dest - input and output of the function. If this parameter is missing the default parameter “ruri.user/ruri.user” will be used, thus translating the request uri.
The “src” variable can be any type of pseudo-variable.
The “dest” variable can be also any type of pseudo-variable, but it must be a writtable one.
This function can be used from REQUEST_ROUTE, BRANCH_ROUTE.
Example 1.13. dp_translate
usage
... dp_translate("240", "$ruri.user/$avp(dest)"); xlog("translated to var $avp(dest) \n"); ...
Example 1.14. dp_translate
usage
... $avp(src) = $ruri.user; dp_translate("$var(x)", "$avp(src)/$var(y)"); xlog("translated to var $var(y) \n"); ...
Example 1.15. dp_translate
usage
... $avp(src) = $uri.user; dp_translate("example_table/$var(x)", "$avp(src)/$var(y)"); xlog("translated to var $var(y) \n"); ...
It will update the translation rules, loading the database info.
Name: dp_reload
Parameters: 1
table_name - Table to be realoaded. If no table is specified, the table specified in the "table_name" parameter (default dialplan) will be reloaded.
MI DATAGRAM Command Format:
:dp_reload: _empty_line_
It will apply a translation rule identified by a dialplan id and an input string.
Name: dp_translate
Parameters: 2
[Table Name/]Dialplan ID - The dpid of the rules used to match the input string. The table name can be ommited. The default table is dialplan.
Input String
MI DATAGRAM Command Format:
:dp_translate: dpid input _empty_line_
The modules requires one table in OpenSIPS database: dialplan.The SQL syntax to create them can be found in dialplan-create.sql script in the database directories in the opensips/scripts folder. You can also find the complete database documentation on the project webpage, http://www.opensips.org/html/docs/db/db-schema-devel.html.