Module: kamailio Branch: master Commit: 20b690a31ee0d3fbaa86fdf87790d842a982bcf5 URL: https://github.com/kamailio/kamailio/commit/20b690a31ee0d3fbaa86fdf87790d842...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2023-11-21T11:36:10+01:00
topos: open db connection in mod init only when checking table version
---
Modified: src/modules/topos/topos_mod.c Modified: src/modules/topos/tps_storage.h
---
Diff: https://github.com/kamailio/kamailio/commit/20b690a31ee0d3fbaa86fdf87790d842... Patch: https://github.com/kamailio/kamailio/commit/20b690a31ee0d3fbaa86fdf87790d842...
---
diff --git a/src/modules/topos/topos_mod.c b/src/modules/topos/topos_mod.c index 40133099bf4..440936f294c 100644 --- a/src/modules/topos/topos_mod.c +++ b/src/modules/topos/topos_mod.c @@ -79,6 +79,9 @@ db_func_t _tpsdbf; /* sruid to get internal uid */ sruid_t _tps_sruid;
+extern str tt_table_name; +extern str td_table_name; + /** module parameters */ static str _tps_db_url = str_init(DEFAULT_DB_URL); int _tps_param_mask_callid = 0; @@ -259,26 +262,24 @@ static int mod_init(void) "provide all functions needed\n"); return -1; } - topos_db_con = _tpsdbf.init(&_tps_db_url); - if(topos_db_con == NULL) { - LM_ERR("failed to open database connection\n"); - goto dberror; - } - if(_tps_version_table_check != 0 - && db_check_table_version(&_tpsdbf, topos_db_con, - &td_table_name, TD_TABLE_VERSION) - < 0) { - DB_TABLE_VERSION_ERROR(td_table_name); - goto dberror; - } - if(_tps_version_table_check != 0 - && db_check_table_version(&_tpsdbf, topos_db_con, - &tt_table_name, TT_TABLE_VERSION) - < 0) { - DB_TABLE_VERSION_ERROR(tt_table_name); - goto dberror; - } - if(topos_db_con) { + if(_tps_version_table_check != 0) { + topos_db_con = _tpsdbf.init(&_tps_db_url); + if(topos_db_con == NULL) { + LM_ERR("failed to open database connection\n"); + goto dberror; + } + if(db_check_table_version( + &_tpsdbf, topos_db_con, &td_table_name, TD_TABLE_VERSION) + < 0) { + DB_TABLE_VERSION_ERROR(td_table_name); + goto dberror; + } + if(db_check_table_version( + &_tpsdbf, topos_db_con, &tt_table_name, TT_TABLE_VERSION) + < 0) { + DB_TABLE_VERSION_ERROR(tt_table_name); + goto dberror; + } _tpsdbf.close(topos_db_con); topos_db_con = NULL; } diff --git a/src/modules/topos/tps_storage.h b/src/modules/topos/tps_storage.h index 65d2c5d8be9..4c2585a1ff6 100644 --- a/src/modules/topos/tps_storage.h +++ b/src/modules/topos/tps_storage.h @@ -85,8 +85,6 @@ typedef struct tps_data int32_t expires; } tps_data_t;
-extern str tt_table_name; -extern str td_table_name; int tps_storage_dialog_find(sip_msg_t *msg, tps_data_t *td); int tps_storage_dialog_save(sip_msg_t *msg, tps_data_t *td); int tps_storage_dialog_rm(sip_msg_t *msg, tps_data_t *td);