diff --git a/src/modules/dialplan/Makefile b/src/modules/dialplan/Makefile index bda93644f4e..b03dc38e037 100644 --- a/src/modules/dialplan/Makefile +++ b/src/modules/dialplan/Makefile @@ -27,6 +27,5 @@ LIBS=$(PCRELIBS) DEFS+=-DKAMAILIO_MOD_INTERFACE SERLIBPATH=../../lib -SER_LIBS+=$(SERLIBPATH)/kmi/kmi SER_LIBS+=$(SERLIBPATH)/srdb1/srdb1 include ../../Makefile.modules diff --git a/src/modules/dialplan/dialplan.c b/src/modules/dialplan/dialplan.c index e7f21a2e2a6..b319607e3db 100644 --- a/src/modules/dialplan/dialplan.c +++ b/src/modules/dialplan/dialplan.c @@ -17,8 +17,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ @@ -50,7 +50,6 @@ #include "../../core/pvar.h" #include "../../core/dset.h" #include "../../core/mem/mem.h" -#include "../../lib/kmi/mi.h" #include "../../core/parser/parse_to.h" #include "../../core/rpc.h" #include "../../core/rpc_lookup.h" @@ -65,12 +64,9 @@ MODULE_VERSION static int mod_init(void); static int child_init(int rank); static void mod_destroy(); -static int mi_child_init(); static int dialplan_init_rpc(void); -static struct mi_root * mi_reload_rules(struct mi_root *cmd_tree,void *param); -static struct mi_root * mi_translate(struct mi_root *cmd_tree, void *param); static int dp_translate_f(struct sip_msg* msg, char* str1, char* str2); static int dp_trans_fixup(void ** param, int param_no); static int dp_reload_f(struct sip_msg* msg); @@ -101,12 +97,6 @@ static param_export_t mod_params[]={ {0,0,0} }; -static mi_export_t mi_cmds[] = { - { "dp_reload", mi_reload_rules, MI_NO_INPUT_FLAG, 0, mi_child_init}, - { "dp_translate", mi_translate, 0, 0, 0}, - { 0, 0, 0, 0, 0} -}; - static cmd_export_t cmds[]={ {"dp_translate",(cmd_function)dp_translate_f, 2, dp_trans_fixup, 0, ANY_ROUTE}, @@ -123,7 +113,7 @@ struct module_exports exports= { cmds, /* exported functions */ mod_params, /* param exports */ 0, /* exported statistics */ - mi_cmds, /* exported MI functions */ + 0, /* exported MI functions */ 0, /* exported pseudo-variables */ 0, /* additional processes */ mod_init, /* module initialization function */ @@ -135,11 +125,6 @@ struct module_exports exports= { static int mod_init(void) { - if(register_mi_mod(exports.name, mi_cmds)!=0) - { - LM_ERR("failed to register MI commands\n"); - return -1; - } if(dialplan_init_rpc()!=0) { LM_ERR("failed to register RPC commands\n"); @@ -210,12 +195,6 @@ static void mod_destroy(void) } -static int mi_child_init(void) -{ - return 0; -} - - static int dp_get_ivalue(struct sip_msg* msg, dp_param_p dp, int *val) { pv_value_t value; @@ -478,113 +457,6 @@ static int dp_reload_f(struct sip_msg* msg) } -static struct mi_root * mi_reload_rules(struct mi_root *cmd_tree, void *param) -{ - struct mi_root* rpl_tree= NULL; - - if (dp_connect_db() < 0) { - LM_ERR("failed to reload rules fron database (db connect)\n"); - return 0; - } - - if(dp_load_db() != 0){ - LM_ERR("failed to reload rules fron database (db load)\n"); - dp_disconnect_db(); - return 0; - } - - dp_disconnect_db(); - - rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); - if (rpl_tree==0) - return 0; - - return rpl_tree; -} - -/* - * mi cmd: dp_translate - * - * - * * */ - -static struct mi_root * mi_translate(struct mi_root *cmd, void *param) -{ - - struct mi_root* rpl= NULL; - struct mi_node* root, *node; - dpl_id_p idp; - str dpid_str; - str input; - int dpid; - str attrs; - str output= {0, 0}; - - node = cmd->node.kids; - if(node == NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - /* Get the id parameter */ - dpid_str = node->value; - if(dpid_str.s == NULL || dpid_str.len== 0) { - LM_ERR( "empty idp parameter\n"); - return init_mi_tree(404, "Empty id parameter", 18); - } - if(str2sint(&dpid_str, &dpid) != 0) { - LM_ERR("Wrong id parameter - should be an integer\n"); - return init_mi_tree(404, "Wrong id parameter", 18); - } - - if ((idp = select_dpid(dpid)) ==0 ){ - LM_ERR("no information available for dpid %i\n", dpid); - return init_mi_tree(404, "No information available for dpid", 33); - } - - node = node->next; - if(node == NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - if(node->next!= NULL) - return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN); - - input= node->value; - if(input.s == NULL || input.len== 0) { - LM_ERR( "empty input parameter\n"); - return init_mi_tree(404, "Empty input parameter", 21); - } - - LM_DBG("trying to translate %.*s with dpid %i\n", - input.len, input.s, idp->dp_id); - if (translate(NULL, input, &output, idp, &attrs)!=0){ - LM_DBG("could not translate %.*s with dpid %i\n", - input.len, input.s, idp->dp_id); - return init_mi_tree(404, "No translation", 14); - } - LM_DBG("input %.*s with dpid %i => output %.*s\n", - input.len, input.s, idp->dp_id, output.len, output.s); - - rpl = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); - if (rpl==0) - goto error; - - root= &rpl->node; - - node = add_mi_node_child(root, 0, "Output", 6, output.s, output.len ); - if( node == NULL) - goto error; - - node = add_mi_node_child(root, 0, "ATTRIBUTES", 10, attrs.s, attrs.len); - if( node == NULL) - goto error; - - return rpl; - -error: - if(rpl) - free_mi_tree(rpl); - return 0; -} - static const char* dialplan_rpc_reload_doc[2] = { "Reload dialplan table from database", 0 @@ -679,7 +551,7 @@ static void dialplan_rpc_translate(rpc_t* rpc, void* ctx) } /* - * RPC command to dump dialplan + * RPC command to dump dialplan */ static void dialplan_rpc_dump(rpc_t* rpc, void* ctx) { @@ -730,7 +602,7 @@ static void dialplan_rpc_dump(rpc_t* rpc, void* ctx) return; } - if (rpc->struct_add(sh, "dd", "PRIO", rulep->pr, + if (rpc->struct_add(sh, "dd", "PRIO", rulep->pr, "MATCHOP", rulep->matchop)<0) { rpc->fault(ctx, 500, "Internal error adding prio"); diff --git a/src/modules/dialplan/doc/dialplan_admin.xml b/src/modules/dialplan/doc/dialplan_admin.xml index 1dfd252cac1..17d011a9fe9 100644 --- a/src/modules/dialplan/doc/dialplan_admin.xml +++ b/src/modules/dialplan/doc/dialplan_admin.xml @@ -12,12 +12,12 @@ &adminguide; - +
Overview This module implements generic string translations based on matching and - replacement rules. It can be used to manipulate the request URI or a PV and to + replacement rules. It can be used to manipulate the request URI or a PV and to translate it to a new format/value. Dialplan can also be used to match a given URI and retrieve a set of attributes based on the match. It is a very flexible module that can be used to handle call routing, prefix rewrites @@ -28,10 +28,10 @@
How it works - At startup the module will load a set of matching and transformation rules from a + At startup the module will load a set of matching and transformation rules from a database. Rules are grouped into dialplans. Every database row will be - stored in memory as a dialplan rule. Each rule will describe how the - matching will be made, how the input value will be modified and which + stored in memory as a dialplan rule. Each rule will describe how the + matching will be made, how the input value will be modified and which attributes that will be set for the matching transformation. @@ -40,12 +40,12 @@ or fnmatch (see 'man fnmatch') matching. Overlapping matching expressions can be controlled via priorities. One priority can have multiple dialplan entries. Priorities need not be numbered with consecutive - numbers. The next higher priority will be used after trying to match all + numbers. The next higher priority will be used after trying to match all entries in one priority. - 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 + 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. This can be used to identify the used rule. @@ -62,12 +62,12 @@ to convert generic numbers to specific numbers (like for emergency numbers). - The module can also be used for detecting a range or sets of numbers mapped - on a service/case - the attribute string can be used to store extra + The module can also be used for detecting a range or sets of numbers mapped + on a service/case - the attribute string can be used to store extra information about the service/case. - Non-SIP string translation can be implemented - like converting country + Non-SIP string translation can be implemented - like converting country names from all possible formats to a canonical format: (UK, England, United Kingdom) -> GB. @@ -97,7 +97,7 @@
External Libraries or Applications - The following libraries or applications must be installed before + The following libraries or applications must be installed before running &kamailio; with this module loaded: @@ -120,7 +120,7 @@ - Default value is + Default value is &defaultdb;. @@ -238,7 +238,7 @@ modparam("dialplan", "match_exp_col", "column_name")
<varname>match_len_col</varname> (string) - The column name to store the length of a string matching the + The column name to store the length of a string matching the match expression. @@ -299,7 +299,7 @@ modparam("dialplan", "repl_exp_col", "column_name")
<varname>attrs_col</varname> (string) - The column name to store the rule's attributes to be set after match (see + The column name to store the rule's attributes to be set after match (see attrs_pvar ) @@ -320,7 +320,7 @@ modparam("dialplan", "attrs_col", "column_name")
<varname>attrs_pvar</varname> (string) - The pseudovariable used to store the rule's attributes, + The pseudovariable used to store the rule's attributes, after translation (when dp_translate() succeeds). This parameter can be an AVP or a script variable ($var()).. @@ -393,13 +393,13 @@ modparam("dialplan", "match_dynamic", 1)
Functions - +
<function moreinfo="none">dp_translate(id, [src[/dest]])</function> - Will try to translate src into dest according to + Will try to translate src into dest according to the translation rules in the dialplan identified by id . If src/dest is missing the default parameter ruri.user/ruri.user will be used, thus translating the request URI user part. If only dest is @@ -419,18 +419,18 @@ modparam("dialplan", "match_dynamic", 1) - integer- the dialplan id is statically + integer- the dialplan id is statically assigned - + - avp var + avp var - the dialplan id is the value of an existing avp variable - script var + script var - the dialplan id is the value of an existing script variable. @@ -450,12 +450,12 @@ modparam("dialplan", "match_dynamic", 1) - the string is the r-uri or r-uri user part - + avp var - - At input the function will get the input string from an existing - avp variable. At output the function will add an avp with the + - At input the function will get the input string from an existing + avp variable. At output the function will add an avp with the value of the output string. @@ -463,7 +463,7 @@ modparam("dialplan", "match_dynamic", 1) script var - - At input the function will get the input string from an existing + - At input the function will get the input string from an existing script variable. At output the function will set an script variable with the value of the output string. @@ -516,58 +516,7 @@ xlog("translated to var $var(y) \n");
- MI Commands - -
- <varname>dp_reload</varname> - - Forces an update of the translation rules from the database. - - - Name: dp_reload - - Parameters: none - - MI DATAGRAM Command Format: - - - :dp_reload: - _empty_line_ - -
- -
- <varname>dp_translate</varname> - - Will apply a translation rule identified by a dialplan - id and an input string. - - - Name: dp_translate - - Parameters: 2 - - - Dial plan ID - - - Input String - - - - MI DATAGRAM Command Format: - - - :dp_translate: - dpid - input - _empty_line_ - -
-
- -
- Exported RPC Commands + RPC Commands
<varname>dialplan.dump</varname> @@ -601,7 +550,7 @@ xlog("translated to var $var(y) \n"); &sercmd; dialplan.reload
- +
<varname>dialplan.translate</varname> @@ -634,7 +583,7 @@ xlog("translated to var $var(y) \n"); Installation The modules requires one table in &kamailio; database: dialplan. - The SQL syntax to create them can be found in dialplan-create.sql + The SQL syntax to create them can be found in dialplan-create.sql script in the database directories in the kamailio/scripts folder. You can also find the complete database documentation on the project webpage, &kamailiodbdocslink;. @@ -679,7 +628,7 @@ attrs: xyz The match_op field specify matching operator, valid values: - 0 - string comparison; + 0 - string comparison; 1 - regular expression matching (pcre);