Explorar el Código

topos: open db connection in mod init only when checking table version

Daniel-Constantin Mierla hace 1 año
padre
commit
20b690a31e
Se han modificado 2 ficheros con 21 adiciones y 22 borrados
  1. 21 20
      src/modules/topos/topos_mod.c
  2. 0 2
      src/modules/topos/tps_storage.h

+ 21 - 20
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;
 		}

+ 0 - 2
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);