Module: kamailio Branch: master Commit: 86a7e90ce196e4942de3eeb278433164568d1c69 URL: https://github.com/kamailio/kamailio/commit/86a7e90ce196e4942de3eeb278433164568d1c69
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2025-12-04T13:23:08+01:00 mtree: parameter char_list set using callback - it has to be set before any "item" parameter --- Modified: src/modules/mtree/mtree.c Modified: src/modules/mtree/mtree.h Modified: src/modules/mtree/mtree_mod.c --- Diff: https://github.com/kamailio/kamailio/commit/86a7e90ce196e4942de3eeb278433164568d1c69.diff Patch: https://github.com/kamailio/kamailio/commit/86a7e90ce196e4942de3eeb278433164568d1c69.patch --- diff --git a/src/modules/mtree/mtree.c b/src/modules/mtree/mtree.c index 5873d8b8294..ac6131890f0 100644 --- a/src/modules/mtree/mtree.c +++ b/src/modules/mtree/mtree.c @@ -39,7 +39,6 @@ #include "mtree.h" -//extern str mt_char_list = {"1234567890*",11}; extern str mt_char_list; extern pv_spec_t pv_value; extern pv_spec_t pv_values; @@ -58,12 +57,23 @@ static m_tree_t **_ptree = NULL; #define MT_CHAR_TABLE_NOTSET 255 static unsigned char _mt_char_table[MT_CHAR_TABLE_SIZE]; +static int _mt_char_table_ready = 0; + /** * */ -void mt_char_table_init(void) +int mt_char_table_init(int nset) { unsigned int i; + + if(_mt_char_table_ready == 1) { + if(nset == 1) { + LM_ERR("prefix char table already initialized\n"); + return -1; + } + return 0; + } + for(i = 0; i < MT_CHAR_TABLE_SIZE; i++) { _mt_char_table[i] = MT_CHAR_TABLE_NOTSET; } @@ -71,6 +81,9 @@ void mt_char_table_init(void) unsigned char ch = mt_char_list.s[i]; _mt_char_table[ch] = (unsigned char)i; } + _mt_char_table_ready = 1; + + return 0; } @@ -212,6 +225,8 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue) return -1; } + mt_char_table_init(0); + LM_DBG("adding to tree <%.*s> of type <%d>\n", pt->tname.len, pt->tname.s, pt->type); diff --git a/src/modules/mtree/mtree.h b/src/modules/mtree/mtree.h index 189c44a204f..7bd87373e12 100644 --- a/src/modules/mtree/mtree.h +++ b/src/modules/mtree/mtree.h @@ -100,7 +100,7 @@ void mt_free_tree(m_tree_t *pt); int mt_print_tree(m_tree_t *pt); void mt_free_node(mt_node_t *pn, int type); -void mt_char_table_init(void); +int mt_char_table_init(int nset); int mt_node_set_payload(mt_node_t *node, int type); int mt_node_unset_payload(mt_node_t *node, int type); diff --git a/src/modules/mtree/mtree_mod.c b/src/modules/mtree/mtree_mod.c index 84925c08e53..6b85c3c6cd1 100644 --- a/src/modules/mtree/mtree_mod.c +++ b/src/modules/mtree/mtree_mod.c @@ -108,6 +108,7 @@ static volatile int mt_reload_flag = 0; int mt_param(modparam_t type, void *val); int mt_item(modparam_t type, void *val); +int mt_set_char_list(modparam_t type, void *val); static int fixup_mt_match(void **param, int param_no); static int fixup_free_mt_match(void **param, int param_no); static int w_mt_match(struct sip_msg *msg, char *str1, char *str2, char *str3); @@ -140,7 +141,7 @@ static param_export_t params[] = { {"tname_column", PARAM_STR, &tname_column}, {"tprefix_column", PARAM_STR, &tprefix_column}, {"tvalue_column", PARAM_STR, &tvalue_column}, - {"char_list", PARAM_STR, &mt_char_list}, + {"char_list", PARAM_STRING | PARAM_USE_FUNC, &mt_set_char_list}, {"fetch_rows", PARAM_INT, &mt_fetch_rows}, {"pv_value", PARAM_STR, &value_param}, {"pv_values", PARAM_STR, &values_param}, @@ -209,13 +210,6 @@ static int mod_init(void) if(mt_fetch_rows <= 0) mt_fetch_rows = 1000; - if(mt_char_list.len <= 0) { - LM_ERR("invalid prefix char list\n"); - return -1; - } - LM_DBG("mt_char_list=%s \n", mt_char_list.s); - mt_char_table_init(); - /* binding to database module */ if(db_bind_mod(&db_url, &mt_dbf)) { LM_ERR("database module not found\n"); @@ -442,6 +436,29 @@ int mt_item(modparam_t type, void *val) return -1; } +int mt_set_char_list(modparam_t type, void *val) +{ + if(val == NULL) + goto error; + + mt_char_list.s = val; + mt_char_list.len = strlen(mt_char_list.s); + + if(mt_char_list.len <= 0) { + LM_ERR("invalid prefix char list\n"); + return -1; + } + LM_DBG("mt_char_list=%s \n", mt_char_list.s); + if(mt_char_table_init(1) < 0) { + LM_ERR("failed to set prefix char list\n"); + return -1; + } + return 0; + +error: + return -1; +} + static int mt_pack_values( m_tree_t *pt, db1_res_t *db_res, int row, int cols, str *tvalue) { _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
